【问题标题】:Problems with a jquery content sliderjquery 内容滑块的问题
【发布时间】:2013-06-09 18:56:34
【问题描述】:

一直在寻找改变点击内容的滑块的年龄,这正是我想要做的:

Slide a div offscreen using jQuery

但由于某种原因,我无法让它工作。我已经从 jsfiddle 页面复制了代码,但它不起作用。我可能搞砸了一些超级基本的东西,但这是我的代码:)

<style>
body {
padding: 0px;    
}

#container {
position: absolute;
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
overflow: hidden;  
}

.box {
position: absolute;
width: 50%;
height: 300px;
line-height: 300px;
font-size: 50px;
text-align: center;
border: 2px solid black;
left: 50%;
top: 100px;
margin-left: -25%;
}

#box1 {
background-color: green;
left: -50%;
}

#box2 {
background-color: yellow;
}

#box3 {
background-color: red;
left: 150%;
}

#box4 {
background-color: orange;
left: 150%;
}

#box5 {
background-color: blue;
left: 150%;
}

</style>


<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.js"></script>

</head>

<body>


<script type="text/javascript">

$('.box').click(function() {
$('.box').each( function() {
    if ($(this).offset().left < 0) {
        $(this).css("left", "150%");
    }
});

$(this).animate({
     left: '-50%'
 }, 500);

 if ($(this).next().size() > 0) {
     $(this).next().animate({
         left: '50%'
     }, 500);
 } else {
     $(this).prevAll().last().animate({
         left: '50%'
     }, 500);
 }
});j


</script>

<div id="container">

<div id="box1" class="box">Div #1</div>
<div id="box2" class="box">Div #2</div>
<div id="box3" class="box">Div #3</div>
<div id="box4" class="box">Div #4</div>
<div id="box5" class="box">Div #5</div>

</div>

【问题讨论】:

    标签: jquery onclick slider


    【解决方案1】:

    你需要输入:

       $(document).ready(function(){
    

    之后

    <script type="text/javascript">
    

    });
    

    之前

    </script>
    

    你的 jquery 版本太旧了..

    【讨论】:

    • 谢谢!解决了它。我也想在 div 内有链接,那么是否可以添加下一个和上一个按钮,这样 div 本身就不会在点击时移动?
    • 是的,有可能,但我帮不了你,我可以,但我会在几分钟内睡觉
    • 这将是一个巨大的帮助
    • 查看这个教程..它会帮助你learningjquery.com/2009/02/…
    【解决方案2】:

    您需要移动页面底部的 javascript(在关闭 body 标签之前)以确保所有 DOM 都已加载,或者使用 jQuery 就绪方法

    $(function(){
       //your code here
    });
    

    此外,您的代码后面还有一个“j”字符串。和建议 - 将 jQuery 版本升级到 1.9.1 http://jsfiddle.net/gZ74f/1/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-24
      相关资源
      最近更新 更多