Jquery在模态视图中scrollLeft调用问题

发布于 2024-09-26 13:37:11 字数 2606 浏览 3 评论 0原文

我有模式,我想在模式视图中插入一些可滚动文本。但是,scrollLeft 在模式视图中不起作用,但如果我将其放在主页上,而不是在模式视图中,则可以工作。

<div id="userList">
    <div class="user">

        <a href="#?w=500" rel="popup1" class="poplight">Open Modal View</a>
    </div>

</div>

<script>
$(document).ready(function(){

    //When you click on a link with class of poplight and the href starts with a # 
    $("#userList a").children().each(function(idy) {

        var popID = $(this).attr('rel'); //Get Popup Name
        var popURL = $(this).attr('href'); //Get Popup href to define size

        //Pull Query & Variables from href URL
        var query= popURL.split('?');
        var dim= query[1].split('&');
        var popWidth = dim[0].split('=')[1]; //Gets the first query string value

        //Fade in the Popup and add close button
        $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');

        //Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
        var popMargTop = ($('#' + popID).height() + 80) / 2;
        var popMargLeft = ($('#' + popID).width() + 80) / 2;

        //Apply Margin to Popup
        $('#' + popID).css({ 
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
        });

        //Fade in Background
        $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
        $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 

        return false;
    });


    //Close Popups and Fade Layer
    $('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
        $('#fade , .popup_block').fadeOut(function() {
            $('#fade, a.close').remove();  
    }); //fade them both out

        return false;
    });


});

</script>


<style>
  div.demo {
  background:#CCCCCC none repeat scroll 0 0;
  border:3px solid #666666;
  margin:5px;
  padding:5px;
  position:relative;
  width:200px;
  height:100px;
  overflow:auto;
  }
  p { margin:10px;padding:5px;border:2px solid #666;width:1000px;height:1000px; }
    </style>



<div  class="popup_block">


  <div class="demo"><h1>lalala</h1><p>Hello</p></div>
<script>$("div.demo").scrollLeft(300);
</script>


</div>

I have modal and I want to insert in modal view some scrollable text .BUt scrollLeft not work in modal view but works if I put it on main page, not in modal view.

<div id="userList">
    <div class="user">

        <a href="#?w=500" rel="popup1" class="poplight">Open Modal View</a>
    </div>

</div>

<script>
$(document).ready(function(){

    //When you click on a link with class of poplight and the href starts with a # 
    $("#userList a").children().each(function(idy) {

        var popID = $(this).attr('rel'); //Get Popup Name
        var popURL = $(this).attr('href'); //Get Popup href to define size

        //Pull Query & Variables from href URL
        var query= popURL.split('?');
        var dim= query[1].split('&');
        var popWidth = dim[0].split('=')[1]; //Gets the first query string value

        //Fade in the Popup and add close button
        $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');

        //Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
        var popMargTop = ($('#' + popID).height() + 80) / 2;
        var popMargLeft = ($('#' + popID).width() + 80) / 2;

        //Apply Margin to Popup
        $('#' + popID).css({ 
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
        });

        //Fade in Background
        $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
        $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 

        return false;
    });


    //Close Popups and Fade Layer
    $('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
        $('#fade , .popup_block').fadeOut(function() {
            $('#fade, a.close').remove();  
    }); //fade them both out

        return false;
    });


});

</script>


<style>
  div.demo {
  background:#CCCCCC none repeat scroll 0 0;
  border:3px solid #666666;
  margin:5px;
  padding:5px;
  position:relative;
  width:200px;
  height:100px;
  overflow:auto;
  }
  p { margin:10px;padding:5px;border:2px solid #666;width:1000px;height:1000px; }
    </style>



<div  class="popup_block">


  <div class="demo"><h1>lalala</h1><p>Hello</p></div>
<script>$("div.demo").scrollLeft(300);
</script>


</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幸福还没到 2024-10-03 13:37:11

确保您尝试滚动的页面实际上是包含内容的页面。模态插件通常会在您调用该函数的那个​​ div 上放置很多额外的 div,并且模态窗口的实际内容可能不在您认为的 div 中。

Make sure that the page you are trying to scroll is actually the one containing content. Modal plugins usually put a lot of extra divs on the one that you call the function on, and its possible that the actual content of the modal window is not in the div you think it is.

从﹋此江山别 2024-10-03 13:37:11

我解决了。我的错误是使用 $(document).ready(function(){});在 .js 文件之上。我删除它并创建
$("div#photoAlbum").mousemove(function(e){});功能。现在,当我将鼠标移动到精确的 div 上时,它正在调用我的scrollLeft 函数。

I solved it. My mistake was using $(document).ready(function(){}); on top of .js file. I remove it and created
$("div#photoAlbum").mousemove(function(e){}); fnction. Now it is calling my scrollLeft function when I move mouse on exact div.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文