Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 动画不使用不同的HTML标记_Javascript_Jquery_Html_Jquery Mobile - Fatal编程技术网

Javascript 动画不使用不同的HTML标记

Javascript 动画不使用不同的HTML标记,javascript,jquery,html,jquery-mobile,Javascript,Jquery,Html,Jquery Mobile,我有一个jQueryMobile HTML标记,它正在工作,但是当我试图使它与我将要使用的不同HTML标记一起工作时,动画不起作用,我尝试使用不同的jQuery方法和函数使其工作。似乎什么都没用 工作示例 需要为每个应用程序实现相同的功能 childrenvar stopAnim=false; 函数animateTile(滚动宽度、初始偏移量、元素){ 如果(!stopAnim){ var$a=要素; $a.animate({left:($a.offset().left==(scrollingW

我有一个jQueryMobile HTML标记,它正在工作,但是当我试图使它与我将要使用的不同HTML标记一起工作时,动画不起作用,我尝试使用不同的jQuery方法和函数使其工作。似乎什么都没用

工作示例

需要为每个应用程序实现相同的功能

childrenvar stopAnim=false;
函数animateTile(滚动宽度、初始偏移量、元素){
如果(!stopAnim){
var$a=要素;
$a.animate({left:($a.offset().left==(scrollingWidth+initialOffset))?-initialOffset:(“-=”+scrollingWidth))},
{ 
持续时间:5000,
放松:"摇摆",,
完成:函数(){
如果($a.offset().left<0){
$(this.css(“左”,滚动宽度);
}              
animateTile(滚动宽度);
}    
});
}
}
$('swrapper ul li')。悬停(
函数(){
var scrollingWidth=$(this).children('div.list-heading').children('h2').width();
警报(滚动宽度);
var elem=$(this.children('div.list-heading')。children('h2');
如果(滚动宽度>330){
滚动宽度=滚动宽度+10;
var initialOffset=$(this).children('div.list-heading').children('h2').offset().left;
stopAnim=false;
animateTile(滚动宽度、初始偏移量、元素);
}
},
函数(){
stopAnim=true;
$(this).children('div.list-heading').children('h2').stop(true,true).css(“left”,“0”);
}
);

您的javascript中有一个错误:

childrenvar stopAnim = false;
应该是

childrenvar_stopAnim = false;
我已删除js错误:

这是小提琴的最终工作版本:

我将在这里发布工作js代码:

var childrenvar, stopAnim = false;

function animateTitle(scrollingWidth, initialOffset, elem) {
    if (!stopAnim) {
        var $a = elem;
        $a.animate({
            left: (($a.offset().left == (scrollingWidth + initialOffset)) ? -initialOffset : ("-=" + scrollingWidth))
        }, {
            duration: 5000,
            easing: 'swing',
            complete: function () {
                if ($a.offset().left < 0) {
                    $(this).css("left", scrollingWidth);
                }
                animateTitle(scrollingWidth);
            }
        });
    }
}
$('#swrapper ul li').hover(

function () {
    var scrollingWidth = $(this).select('div.list-heading').children().select('h2').width();
    var elem = $(this).select('div.list-heading').children().select('h2');
    if (scrollingWidth > 330) {
        scrollingWidth = scrollingWidth + 10;
        var offset = $(this).select('div.list-heading').children().select('h2').offset();
        if (offset !== null) {
            var initialOffset = offset.left;
            stopAnim = false;
            animateTitle(scrollingWidth, initialOffset, elem);
        }
    }
},

function () {
    stopAnim = true;
    $(this).select('div.list-heading').children().select('h2').stop(true, true).css("left", "0");
});
var childrenvar,stopAnim=false;
函数animateTile(滚动宽度、初始偏移量、元素){
如果(!stopAnim){
var$a=要素;
$a.animate({
左:($a.offset().left==(scrollingWidth+initialOffset))?-initialOffset:(“-=”+scrollingWidth))
}, {
持续时间:5000,
放松:"摇摆",,
完成:函数(){
如果($a.offset().left<0){
$(this.css(“左”,滚动宽度);
}
animateTile(滚动宽度);
}
});
}
}
$('swrapper ul li')。悬停(
函数(){
var scrollingWidth=$(this).select('div.list-heading').children().select('h2').width();
var elem=$(this).select('div.list-heading').children().select('h2');
如果(滚动宽度>330){
滚动宽度=滚动宽度+10;
var offset=$(this).select('div.list-heading').children().select('h2').offset();
如果(偏移量!==null){
var initialOffset=offset.left;
stopAnim=false;
animateTile(滚动宽度、初始偏移量、元素);
}
}
},
函数(){
stopAnim=true;
$(this).select('div.list-heading').children().select('h2').stop(true,true).css(“left”,“0”);
});

您的javascript中有一个错误:

childrenvar stopAnim = false;
应该是

childrenvar_stopAnim = false;
我已删除js错误:

这是小提琴的最终工作版本:

我将在这里发布工作js代码:

var childrenvar, stopAnim = false;

function animateTitle(scrollingWidth, initialOffset, elem) {
    if (!stopAnim) {
        var $a = elem;
        $a.animate({
            left: (($a.offset().left == (scrollingWidth + initialOffset)) ? -initialOffset : ("-=" + scrollingWidth))
        }, {
            duration: 5000,
            easing: 'swing',
            complete: function () {
                if ($a.offset().left < 0) {
                    $(this).css("left", scrollingWidth);
                }
                animateTitle(scrollingWidth);
            }
        });
    }
}
$('#swrapper ul li').hover(

function () {
    var scrollingWidth = $(this).select('div.list-heading').children().select('h2').width();
    var elem = $(this).select('div.list-heading').children().select('h2');
    if (scrollingWidth > 330) {
        scrollingWidth = scrollingWidth + 10;
        var offset = $(this).select('div.list-heading').children().select('h2').offset();
        if (offset !== null) {
            var initialOffset = offset.left;
            stopAnim = false;
            animateTitle(scrollingWidth, initialOffset, elem);
        }
    }
},

function () {
    stopAnim = true;
    $(this).select('div.list-heading').children().select('h2').stop(true, true).css("left", "0");
});
var childrenvar,stopAnim=false;
函数animateTile(滚动宽度、初始偏移量、元素){
如果(!stopAnim){
var$a=要素;
$a.animate({
左:($a.offset().left==(scrollingWidth+initialOffset))?-initialOffset:(“-=”+scrollingWidth))
}, {
持续时间:5000,
放松:"摇摆",,
完成:函数(){
如果($a.offset().left<0){
$(this.css(“左”,滚动宽度);
}
animateTile(滚动宽度);
}
});
}
}
$('swrapper ul li')。悬停(
函数(){
var scrollingWidth=$(this).select('div.list-heading').children().select('h2').width();
var elem=$(this).select('div.list-heading').children().select('h2');
如果(滚动宽度>330){
滚动宽度=滚动宽度+10;
var offset=$(this).select('div.list-heading').children().select('h2').offset();
如果(偏移量!==null){
var initialOffset=offset.left;
stopAnim=false;
animateTile(滚动宽度、初始偏移量、元素);
}
}
},
函数(){
stopAnim=true;
$(this).select('div.list-heading').children().select('h2').stop(true,true).css(“left”,“0”);
});

@Floadu88:如果我们只能在你的修复中设置h2标记的动画,那就太好了。无论如何,我感谢你的帮助。伟大的工作感谢你的时间。@KnowledgeSeaker很高兴我能help@Floadu88:如果我们只能在你的修复中设置h2标记的动画,那就太好了。无论如何,我感谢你的帮助。伟大的工作感谢你的时间。@KnowledgeSeeker很高兴我能帮助你