jQuery动画设置不平滑
我在这里有wordpress网站,我用这个jQuery脚本将我的标题背景设置为滑块。唯一的问题是,在JSFIDLE中,所有的过渡看起来都很平滑,而在我的网站上,没有过渡,只有即时闪现和图像更改jQuery动画设置不平滑,jquery,wordpress,animation,Jquery,Wordpress,Animation,我在这里有wordpress网站,我用这个jQuery脚本将我的标题背景设置为滑块。唯一的问题是,在JSFIDLE中,所有的过渡看起来都很平滑,而在我的网站上,没有过渡,只有即时闪现和图像更改 $(document).ready(function () { var img_array = [1, 2, 3, 4, 5], newIndex = 0, index = 0, interval = 8000; (function changeBg() { // ---
$(document).ready(function () {
var img_array = [1, 2, 3, 4, 5],
newIndex = 0,
index = 0,
interval = 8000;
(function changeBg() {
// --------------------------
// For random image rotation:
// --------------------------
// newIndex = Math.floor(Math.random() * 10) % img_array.length;
// index = (newIndex === index) ? newIndex -1 : newIndex;
// ------------------------------
// For sequential image rotation:
// ------------------------------
index = (index + 1) % img_array.length;
$('#branding').css('backgroundImage', function () {
$('#branding').animate({
backgroundColor: 'transparent'
}, 2000, function () {
setTimeout(function () {
$('#branding').animate({
backgroundColor: 'rgb(255,255,255)'
}, 2000);
}, 4000);
});
return 'url(http://placekitten.com/150/15' + img_array[index] +')';
});
setTimeout(changeBg, interval);
})();
});
检查您的控制台:
Uncaught ReferenceError: jQuery is not defined
必须包含jQuery才能实现动画
将此添加到您的头部部分:
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
添加header.php文件
<?php
wp_enqueue_script('jquery');
?>
在头文件中,jquery脚本也没有正确导入。
控制台中未定义jQuery。将jQuery包含在标题部分。您需要使用jQuery 在functions.php文件末尾添加以下行:
function modify_jquery() {
if (!is_admin()) {
// comment out the next two lines to load the local copy of jQuery
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', false, '1.9.1');
wp_enqueue_script('jquery');
}
}
add_action('init', 'modify_jquery');
您在
控制台中有jQuery未定义
错误
!!尝试增加计时器延迟值谢谢回复,我已经插入了这个函数,但是动画看起来仍然不平滑,但是在JSFIDLE中,它可以正常工作。尝试更改jQuery版本(1.8.1到1.9.1)