2016-12-15 4 views
0

私のメールチャットボット用のチャットボックスを設計しています。私はwebdesignとJavaScriptに関する知識はほとんど持っていません。私は自分のチャットボックスを最小化または閉じることができません。私はいくつかのサイトからその機能のためにいくつかの.jsコードをコピーしようとしましたが、今まで働いたことはありません。私のチャットボックスの最小化と閉じるボタンのJavascriptは機能しません

<html> 
    <head> 
    <title>chatbox for bot</title> 
    </head> 
    <style> 
.popup-wrapper { 
    position: fixed; 
    background-color: #FFFFFF; 
    right: 50px; 
    bottom: 0px; 
    padding: 0px; 
    height: 410px; 
    width: 250px; 
    z-index: 200; 
    -moz-border-radius:10px 10px 0px 0px; 
    border-radius:10px 10px 0px 0px; 
} 

.popup-header { 
    background-color: #5b6fc7; 
    color: #ffffff; 
    height: 10%; 
    padding: 10px 10px 5px 10px; 
    -moz-border-radius:10px 10px 0px 0px; 
    border-radius:10px 10px 0px 0px; 

} 

.popup-tab { 
    position: fixed; 
    right: 50px; 
    bottom: 0px; 
    padding: 10px 10px 5px 10px; 
    background-color: #5b6fc7; 
    height: 40px; 
    width: 250px; 
    z-index: 200; 
    cursor: pointer; 
    -moz-border-radius:10px 10px 0px 0px; 
    border-radius:10px 10px 0px 0px; 
    color: #ffffff; 
} 

.botMessage { 
    background-color: #eeeeee; 
    position: relative; 
    padding: 5px; 
    margin: 5px; 
    display: inline-block; 
    -moz-border-radius:10px 10px 10px 10px; 
    border-radius:10px 10px 10px 10px; 
} 

.humanMessage { 
    background-color: #5b6fc7; 
    position: relative; 
    color: #FFF; 
    padding: 5px; 
    margin: 5px; 
    display: inline-block; 
    float: right; 
    -moz-border-radius:10px 10px 10px 10px; 
    border-radius:10px 10px 10px 10px; 
} 


.close-chat, .minimize-chat { 
    cursor: pointer; 
    margin-right: 5px; 
    float: right !important; 
} 

.convo { 
    height: 320px; 
    padding: 5px; 
    border-style: solid; 
    border-width: 1px; 
    border-color: #eeeeee; 
} 

.chatlog { 
    width: 750px; 
    height: 300px; 
    padding: 5px; 
    border: 1px solid #000000; 
} 

.scroll { 
    overflow-y: auto; 
    overflow-x: hidden; 
} 

.agentMessage { 
    background-color: #5cb85c; 
    position: relative; 
    padding: 5px; 
    margin: 5px; 
    display: inline-block; 
    -moz-border-radius:10px 10px 10px 10px; 
    border-radius:10px 10px 10px 10px; 
} 

form#talkform { 
    width 
    height: 50px; 
    padding: 10px 10px 5px 10px; 
    -moz-border-radius:10px 10px 10px 10px; 
    border-radius:10px 10px 10px 10px; 



/* 
.say something { 
    width: 0px; 
    border-color: #ffffff; 
    border-style: solid; 
} 
*/ 

} 
.hidden { 
    display: none !important; 
    visibility: hidden !important; 
} 
* { 
    -webkit-box-sizing: border-box; 
    -moz-box-sizing: border-box; 
     box-sizing: border-box; 
    box-sizing: border-box; 
} 

#popup-WrapperClose { 
    width: 15px; 
    height: 15px; 
    z-index: 12; 
    border-radius: 50%; 
    background-color: red; 
    position: absolute; 
    top: 15px; 
    right: 15px; 
} 

#popup-WrapperMini { 
    width: 15px; 
    height: 15px; 
    z-index: 12; 
    border-radius: 50%; 
    background-color: green; 
    position: absolute; 
    top: 15px; 
    right: 45px; 
} 

img { 
    display: block; 
    margin: 80px auto -60px auto; 
} 
</style> 
    <body> 
    <div class="popup-wrapper"> 
    <div class="popup-header"> 
    <b> 
    Talk to 
    <span class="botname">Ella</span> 
    </b> 
    <input id="popup-WrapperClose" type="button" onclick="windowClose();"></input> 
    <input id="popup-WrapperMini" type="button" onclick="windowMin();"></input> 
    </div> 
    <div class="popup-chat"> 
    <div class="response hidden"></div> 
    <div class="convo scroll"> 
    <div class="humanMessage"> 
    <div class="usersay">&nbsp;</div> 
    </div> 
    <br></br> 
    <div class="botMessage"> 
    <div class="ella"> 
    <div class="botsay"></div> 
    </div> 
    </div> 
    <br></br> 
    </div> 
     <form method="post" name="talkform" id="talkform" action="index.php"> 
     <form id="talkform" class="talkform"> 
        <input id="say" name="say" placeholder="say something" type="text"> 
        <input id="say-button" class="say-button" name="say-button" value="say" type="submit"> 
       </form> 
       </form> 
</div> 
</div> 

<script> 
    $('#popup-wrapperClose').click(function() { 
     $("#popup-wrapper").hide(300); 
    }); 

    $('#popup-wrapperMini').click(function() { 
     if (minimize === false) { 
     $("#popup-wrapperMini").hide(); 
     $('#popup-wrapper').css('display','block'); 
     minimize = true; 
     } else { 
     $("#popup-wrapper").show(); 
     $('#popup-wrapper').css('display','none'); 
     minimize = false; 
     } 
    }); 
    return false; 
}); 
</script> 
    </body> 
</html> 

答えて

1

あなたのコードに修正するためにいくつかのことをあります:あなたはIDセレクタ(#)とあなたの<div>のどれを使用しているあなたのjQueryコードで

1)のIDを持っています。

2)あなたが最小化と閉じるボタンの間違ったクラス名を使用している:あなたはJavaScriptで)

popup-wrapperMini 

3:HTMLで

を:JSで

popup-WrapperMini 

var最小化を使用していますが、それはあなたから来ていますか?

私はJSFiddleを最小限の作業で作った。どうぞご覧ください: https://jsfiddle.net/dudu84/ue0c94q7/1/

希望すると助かります!

+0

こんにちはベネディクト!それは奇妙だ。それは閉じて最小化しています。何があなたのために働いていないのですか?宜しくお願いします。 – deChristo

+0

申し訳ありません!私は私がコメントしていた間違いをした。できます。あなたのコメントdeChristoに感謝します。フィドルはまさに私が望んでいたものです。しかし、私は同じを実装しようとし、それはまだ動作しません。私もフィドルをデバッグし、まったく同じことをしようとしましたが、何もしませんでした。私がフィドルをデバッグしたとき、私はこの ""という頭の部分に気付きました。、私はこれをダウンロードして何とかリンクしていますか? –

+0

さて、実際にjquery-3.1.1.jsをダウンロードしてチャットボックスのディレクトリにコピーし、htmlとvoilaでリンクしました。IT WORKS !!! deChristoのおかげで本当に感謝しています....あなた、ロック! –

0

要素を参照するために$を使用しているコードが見つかった場合は、コードがjQueryでありプレーンなJavaScriptではない可能性があることを示すヒントです。 jQueryをロードしていない限り、動作しません。ここに純粋なJavaScriptの例があります。 globalminimizeの宣言に注目してください。

また、divsにはIDが必要で、popup-wrapperに追加され、新しい外部wrapperに追加されました。

popup-wrapperは、ポップアップを最小限にするために使用され、wrapperはclose関数で使用されます。

UPDATE

コード今最小限にし、ここでupdated jsfiddle

HTML

<title>chatbox for bot</title> 
<div id="wrapper"> 
    <div class="popup-header" class="popup-header" > 
    <b> 
      Talk to 
      <span class="botname">Ella</span> 
     </b> 
    <input id="popup-WrapperMini" type="button" onclick="windowMin();"> 
    <input id="popup-WrapperClose" type="button" onclick="windowClose();"> 
    </div> 
    <div id="popup-wrapper" class="popup-wrapper"> 
    <div class="popup-chat"> 
     <div class="response hidden"></div> 
     <div class="convo scroll"> 
     <div class="humanMessage"> 
      <div class="usersay">&nbsp;</div> 
     </div> 
     <br> 
     <div class="botMessage"> 
      <div class="ella"> 
      <div class="botsay"></div> 
      </div> 
     </div> 
     <br> 
     </div> 
     <form method="post" name="talkform" id="talkform" action="index.php"> 
     <form id="talkform" class="talkform"> 
      <input id="say" name="say" placeholder="say something" type="text"> 
      <input id="say-button" class="say-button" name="say-button" value="say" type="submit"> 
     </form> 
     </form> 
    </div> 
    </div> 
</div> 

をされていない、最小限のJavascript

を移行します

CSS

.popup-wrapper { 
     /* position: fixed; */ 
     background-color: #FFFFFF; 
     /* right: 50px; */ 
     bottom: 0px; 
     padding: 0px; 
     max-height: 410px; 
     width: 250px; 
     z-index: 200; 
     -moz-border-radius:10px 10px 0px 0px; 
     border-radius:10px 10px 0px 0px; 
    -webkit-transition: max-height 0.5s ease-in; 
    -moz-transition: max-height 0.5s ease-in; 
    -ms-transition: max-height 0.5s ease-in; 
    -o-transition: max-height 0.5s ease-in; 
    transition: max-height 0.5s ease-in; 
    overflow: hidden; 
    } 

    .popup-header { 
     background-color: #5b6fc7; 
     color: #ffffff; 
     height: 10%; 
     width: 250px; 
     padding: 10px 10px 5px 10px; 
     -moz-border-radius:10px 10px 0px 0px; 
     border-radius:10px 10px 0px 0px; 

    } 

    .popup-tab { 
     position: fixed; 
     right: 50px; 
     bottom: 0px; 
     padding: 10px 10px 5px 10px; 
     background-color: #5b6fc7; 
     height: 40px; 
     width: 250px; 
     z-index: 200; 
     cursor: pointer; 
     -moz-border-radius:10px 10px 0px 0px; 
     border-radius:10px 10px 0px 0px; 
     color: #ffffff; 
    } 

    .botMessage { 
     background-color: #eeeeee; 
     position: relative; 
     padding: 5px; 
     margin: 5px; 
     display: inline-block; 
     -moz-border-radius:10px 10px 10px 10px; 
     border-radius:10px 10px 10px 10px; 
    } 

    .humanMessage { 
     background-color: #5b6fc7; 
     position: relative; 
     color: #FFF; 
     padding: 5px; 
     margin: 5px; 
     display: inline-block; 
     float: right; 
     -moz-border-radius:10px 10px 10px 10px; 
     border-radius:10px 10px 10px 10px; 
    } 


    .close-chat, .minimize-chat { 
     cursor: pointer; 
     margin-right: 5px; 
     float: right !important; 
    } 

    .convo { 
     height: 320px; 
     padding: 5px; 
     border-style: solid; 
     border-width: 1px; 
     border-color: #eeeeee; 
    } 

    .chatlog { 
     width: 750px; 
     height: 300px; 
     padding: 5px; 
     border: 1px solid #000000; 
    } 

    .scroll { 
     overflow-y: auto; 
     overflow-x: hidden; 
    } 

    .agentMessage { 
     background-color: #5cb85c; 
     position: relative; 
     padding: 5px; 
     margin: 5px; 
     display: inline-block; 
     -moz-border-radius:10px 10px 10px 10px; 
     border-radius:10px 10px 10px 10px; 
    } 

    form#talkform { 
     /* width */ 
     height: 50px; 
     padding: 10px 10px 5px 10px; 
     -moz-border-radius:10px 10px 10px 10px; 
     border-radius:10px 10px 10px 10px; 



     /* 
     .say something { 
     width: 0px; 
     border-color: #ffffff; 
     border-style: solid; 
     } 
     */ 

    } 
    .hidden { 
     display: none !important; 
     visibility: hidden !important; 
    } 
    * { 
     -webkit-box-sizing: border-box; 
     -moz-box-sizing: border-box; 
     box-sizing: border-box; 
     box-sizing: border-box; 
    } 

    #popup-WrapperClose { 
     width: 15px; 
     height: 15px; 
     z-index: 12; 
     border-radius: 50%; 
     background-color: red; 
     /* position: absolute; */ 
     top: 15px; 
     margin-left: 5px; 
     /* right: 15px; */ 
    } 

    #popup-WrapperMini { 
     width: 15px; 
     height: 15px; 
     z-index: 12; 
     border-radius: 50%; 
     background-color: green; 
     /* position: absolute; */ 
     top: 15px; 
     margin-left: 100px; 
     /* right: 45px; */ 
    } 

    img { 
     display: block; 
     margin: 80px auto -60px auto; 
    } 

.wrapper-min{ 
    -webkit-transition: max-height 0.5s ease-out; 
    -moz-transition: max-height 0.5s ease-out; 
    -ms-transition: max-height 0.5s ease-out; 
    -o-transition: max-height 0.5s ease-out; 
    transition: max-height 0.5s ease-out; 
    overflow: hidden; 
    max-height: 0; 
} 
+0

div-id ..のコメントとクイック・ポイント・アウトのおかげで、あなたが提供したリンク上のフィドルはうまくいきません。多分あなたが逃した何か。 –

+0

申し訳ありません。フィドルは修正されています。上記のコードは正しいものであり、変更されていません。 – mseifert

+0

さて、ありがとうございました...今、大丈夫です... "の"幅はどのようにしてチャットボックス全体と同じになるのですか?私のHTMLの他の要素を表示し続けるので、 ""。 –

関連する問題