【问题标题】:Dynamically change mobile content slider width using jquery for portrait and landscape使用 jquery 为纵向和横向动态更改移动内容滑块宽度
【发布时间】:2013-05-29 22:56:06
【问题描述】:

当手机从纵向旋转到横向时,如何动态更改使用jQuery设置的内容滑块的宽度和高度?客户正在为他们的网站使用“allinone”内容滑块。此内容滑块的宽度和高度是使用 jQuery 设置的,代码如下:

jQuery(function() {
        jQuery('#allinone_contentSlider_imposing').allinone_contentSlider({
            width: 300,
            height: 300
        });     
    });

我想在手机从纵向切换到横向时动态更改滑块的宽度和高度,但我的javascript技能不够好。我尝试使用 $(window).width() 和 resize() 事件来定义一个变量,如下所示:

jQuery(function() {
    function updateWidth() {
        var $containerWidth = $(window).width();
    }
    updateWidth();
            $(window).resize(function() {
                updateWidth();
            });
    jQuery('#allinone_contentSlider_imposing').allinone_contentSlider({
        width: $containerWidth,
        height: 300
    });     
});

不幸的是,上面的代码未能定义导致滑块不显示的宽度。顺便说一句,这不是一个仅限移动设备的网站。也许有更好的方法来解决这个问题。接受建议。

【问题讨论】:

    标签: jquery html css


    【解决方案1】:

    jQuery(document).ready(function(){

    vp_width = jQuery(window).width();
    
    if (vp_width <= 650) {
    //alert('mobile');
    
    //Add some Jquery here to change the height and width of the banner?
    
    
    )};
    

    不确定这是否有帮助,如果您知道设备的宽度,您也许可以像上面那样定位宽度,然后设置一些 CSS?希望这会有所帮助,如果没有,请道歉!

    【讨论】:

    • 你的想法在最初改变宽度方面是成功的。但是当手机从纵向变成横向(反之亦然)时,需要刷新浏览器以反映宽度的新变化。也许我需要将此绑定到调整大小事件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多