0

所以我创建了 javascript 滑块,当它转到下一个选项卡时,它会自动向上拉页面。你可以在你的页面中测试它,你会看到,如何解决这个问题?它会向上拉页面,就像会有 href="#top" 和 ,但没有类似的东西。

代码 -

    <script type="text/javascript">
        jQuery(document).ready(function() {
            var time = <?php echo $data['tab1_speed']; ?>;          
            var tripleboxTitle = jQuery("triplebox-tab-title");
            setInterval(function() {
                tripleboxTitle.click(function(){
                    clearInterval();
                });
                var currentTab = jQuery('.triplebox-tab-active').attr("tab");
                var newTab = Number(currentTab)+1;
                if(newTab > 3) {
                    newTab = 1;
                }
                console.log(newTab);
                jQuery(".triplebox-tab-title").removeClass('triplebox-tab-active');
                jQuery('#triplebox-widget-tab'+newTab).addClass('triplebox-tab-active');
                jQuery(".triplebox-tab-default").hide();
                jQuery(".triplebox-tab-default").removeClass('triplebox-tab-default');
                jQuery("#triplebox-widget-tab"+newTab+"-widget").addClass('triplebox-tab-default').fadeIn(300);
            }, time);
        });
    </script>
    <a id="triplebox-widget-tab1" tab="1" class="triplebox-tab-title triplebox-tab-active" <?php if($data['use_color'] == 'default') { ?>style="color: <?php echo $data['color_text']; ?>; background: <?php echo $data['color_tabs']; ?>;" <?php } ?>><?php echo $data['tab1_name']; ?></a>
    <a id="triplebox-widget-tab2" tab="2" class="triplebox-tab-title" <?php if($data['use_color'] == 'default') { ?>style="color: <?php echo $data['color_text']; ?>; background: <?php echo $data['color_tabs']; ?>;" <?php } ?>><?php echo $data['tab2_name']; ?></a>
    <a id="triplebox-widget-tab3" tab="3" class="triplebox-tab-title" <?php if($data['use_color'] == 'default') { ?>style="color: <?php echo $data['color_text']; ?>; background: <?php echo $data['color_tabs']; ?>;" <?php } ?>><?php echo $data['tab3_name']; ?></a>

    <div id="triplebox-widget-tab1-widget" class="triplebox-widget triplebox-tab-default" <?php if($data['use_color'] == 'default') { ?>style="background: <?php echo $data['color_content']; ?>; color: <?php echo $data['color_text']; ?>;"<?php } ?>>
        <?php echo $content; ?>
    </div>
    <div id="triplebox-widget-tab2-widget" class="triplebox-widget" style=" <?php if($data['use_color'] == 'default') { ?>background: <?php echo $data['color_content']; ?>; color: <?php echo $data['color_text']; ?>;<?php } ?> display: none;">
        <?php echo $content2; ?>
    </div>
    <div id="triplebox-widget-tab3-widget" class="triplebox-widget" style=" <?php if($data['use_color'] == 'default') { ?>background: <?php echo $data['color_content']; ?>; color: <?php echo $data['color_text']; ?>;<?php } ?> display: none;">
        <?php echo $content3; ?>
    </div>

另外,为什么我的 clearInterval(); 不工作?它仍在继续滚动。如何让它停止?

4

1 回答 1

0

您需要传递给函数“intervalID”

https://developer.mozilla.org/en/DOM/window.setInterval#Example

所以;

var tripleboxTitle = jQuery("triplebox-tab-title");
var myIntvID = setInterval(function() {
...
tripleboxTitle.click(function(){
   clearInterval(myIntvID);
});
于 2012-06-09T11:41:06.213 回答