淡出CSS Jquery OnClick事件

时间:2017-09-01 15:19:10

标签: jquery css onclick

我试图通过更改epochs = 30 batch_size = 64 hidden_neurons = 32 output_size = 1 # Create the model model = Sequential() model.add(LSTM(hidden_neurons, input_shape=(X_train.shape[1], X_train.shape[2]))) model.add(Dense(output_size, activation = 'elu')) model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy']) print(model.summary()) model.fit(X_train, y_train, epochs=epochs, batch_size=batch_size) scores = model.evaluate(X_test, y_test, batch_size=batch_size, verbose=0) print("Model Accuracy: %.2f%%" % (scores[1]*100)) 事件的css属性淡出当前div。 div已成功隐藏但动画不起作用。关于为什么的任何想法?

onclick

1 个答案:

答案 0 :(得分:1)

为什么不创建一个函数并添加一个事件。尽量避免添加内联脚本。这不是一个好习惯,下面是一个示例:



var fade_speed = 50; //500 ms

function fadeOut() {
    var fadeTarget = document.getElementById("clickme");
    var fadeEffect = setInterval(function () {
        if (!fadeTarget.style.opacity) {
            fadeTarget.style.opacity = 1;
        }
        if (fadeTarget.style.opacity < 0.1) {
            fadeTarget.style.display = "none";
            clearInterval(fadeEffect);
        } else {
            fadeTarget.style.opacity -= 0.1;
        }
    }, fade_speed);
}

document.getElementById("clickme").addEventListener('click', fadeOut);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="clickme" style="position:relative;">
  Click me to hide
</div>
<div id="thevideo" style="display: none;">
  <iframe id="iframe" width="1280" height="720" src="https://www.youtube.com/truncated..." frameborder="0" allowfullscreen></iframe>
</div>
<span>TEST, ignore me</span>
&#13;
&#13;
&#13;

选项2,jQuery

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<div id="clickme" style="position:relative;">
  Click me to hide
</div>
<div id="thevideo">
  <iframe id="iframe" width="1280" height="720" src="https://www.youtube.com/truncated..." frameborder="0" allowfullscreen></iframe>
</div>
<span>TEST, ignore me</span>

<script>
  // A $( document ).ready() block.
  $(document).ready(function() {

    $('#clickme').click(function() {
      $('#thevideo').fadeOut(500);
    });

  });
</script>
&#13;
&#13;
&#13;