【问题标题】:Iterate through each attribute in Jquery loop遍历 Jquery 循环中的每个属性
【发布时间】:2021-03-11 21:56:39
【问题描述】:

我目前正忙于自制的 JQuery 滑块。对于客户,我想根据网页上的位置更改每张幻灯片。当我在第一个场景时,然后单击下一步,我想显示第二个场景,依此类推。当我在第六场时,我想回到第一场。

我尝试了几件事,但不知何故我找不到解决方案。希望你们能指出我正确的方向。

    <div id="-scene-wrapper">  
        <a href="#" class="previous"><h2>Back</h2></a> 
        <a href="#" class="next"><h2>Next</h2></a>  
        <div id="scene1" class="scenes">
            <h2>Scene 1</h2>
        </div>
        <div id="scene2" class="scenes">
            <h2>Scene 2</h2>
        </div>
        <div id="scene3" class="scenes">
            <h2>Scene 3</h2>
        </div>
        <div id="scene4" class="scenes">
            <h2>Scene 4</h2>
        </div>
        <div id="scene5" class="scenes">
            <h2>Scene 5</h2>
        </div>
        <div id="scene6" class="scenes">
            <h2>Scene 6</h2>
        </div>
    </div>
$(window).scroll(function () {
    $(".scenes").each(function (index) {
        $.fn.isInViewport = function () {
            var ScrollTop = $(window).scrollTop();
            console.log(ScrollTop);
        };

        $('.next').click(function(event){
            event.preventDefault();
            console.log(index);
            //Magic code 
        })

        $('.previous').click(function(event){
            event.preventDefault();
            console.log(index);
            //Magic code 
        })
    });
});

【问题讨论】:

  • 先把类名整理出来。在html结构中,你有class="Next",在代码中$('.next')...
  • 感谢您的评论。
  • 您的问题还有意义吗?
  • 是的,我还是有这个问题
  • 我认为我以非常准确的方式解决了问题 ;-)

标签: html jquery scroll slider each


【解决方案1】:

根据上面的HTML代码,我解决了这个问题!很想听听您对此解决方案的看法。

解决办法如下:

【讨论】:

  • 不错的解决方案先生
猜你喜欢
  • 1970-01-01
  • 2018-04-13
  • 2011-03-09
  • 1970-01-01
  • 1970-01-01
  • 2023-01-11
  • 1970-01-01
  • 1970-01-01
  • 2016-05-26
相关资源
最近更新 更多