忘记滚动历史记录,不使用window.scroll()

时间:2015-01-17 02:53:25

标签: javascript jquery html scroll

我无法将window.scroll(0,0)放在任何地方,它会中断我的过渡。因为项目和内容并排排列,当我向一侧滚动,然后我回来时,滚动历史不再相同



$(function(){
    $('.item').on('click', function(){
        $(this).addClass('slideLeftItem');
        $('.content').show(0,'', function(){
            $('#back').show();
        }).addClass('slideRightContent');
    });
    
    
    $('#back').on('click',function(){
        
        $('.item').show().removeClass('slideLeftItem');
        $(this).hide();
        $('.content').removeClass('slideRightContent').once('transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd', 
            function() {
                 $(this).hide();
            });
        });
});

.content{
    display:none;
    position: absolute;
right: -200px;
top: 0px;
background: blue;
transition: 0.4s;
}

.item{

transition: 0.4s;
}

.slideRightContent{
    right: 0px;
}


.slideLeftItem{
    left: -200px;
}

#back{
    display:none;
    height: 20px !Important;
    background: grey !Important;

}

.content, .item{
    width:200px;
    height: 200px;
    background: red;
}

.phone{
  position: relative;
  overflow: hidden;
    overflow-y:scroll;
  transition: 0.4s;
   width:200px;
    border: 10px solid #000;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div id="back">< back</div>


<br>
<div class="phone">
    
<div class="item">item</div>
<div class="content">My content</div>

            
    <div class="item">item 2</div>
<div class="content">My content 2</div>
    
            
    <div class="item">item 3</div>
<div class="content">My content 3 is long My content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is long My content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is long My content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is longMy content 3 is long</div>
    
</div>
&#13;
&#13;
&#13;

正如你在上面的演示中看到的那样,当内容页面很长并且你向上滚动(或使用window.scroll(0,0))来阅读时,你点击回来,它不会留在哪里用户以前在。

0 个答案:

没有答案