Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 在magento中,随着移动方向的改变而改变div的宽度_Jquery_Magento_Jquery Mobile_Magento 1.7 - Fatal编程技术网

Jquery 在magento中,随着移动方向的改变而改变div的宽度

Jquery 在magento中,随着移动方向的改变而改变div的宽度,jquery,magento,jquery-mobile,magento-1.7,Jquery,Magento,Jquery Mobile,Magento 1.7,我正在研究magento移动主题 我想在手机屏幕的基础上设置li的宽度 因为我用的是 <script> jQuery(function() { var width= jQuery(window).width(); jQuery(".press_li").width(width*0.75); }); </script> jQuery(函数(){ var width=jQuery(window

我正在研究magento移动主题

我想在手机屏幕的基础上设置li的宽度

因为我用的是

  <script>
        jQuery(function() {
        var width= jQuery(window).width();
        jQuery(".press_li").width(width*0.75);
       });      
 </script>

jQuery(函数(){
var width=jQuery(window).width();
jQuery(“.press_li”)。宽度(宽度*0.75);
});      
它起作用了。但当方向改变时,宽度并没有改变。为此,我尝试使用jQuery mobile,但当我包含jQuery时,其他jQuery将停止工作。

JavaScript正在使用。
width
变量在绑定到文档就绪状态的匿名函数的范围内

作为修复,您可以在
fixWidth
处理程序上重复
var width…
行,或者将该处理程序和方向更改活页夹都放在第一个文档就绪函数处理程序中

jQuery mobile不包括jQuery本身,这是移动版本工作所必需的库


无论如何,我强烈建议将用作一种良好的实践,而不是这样做。

您可以使用下一个代码来解决您的问题

function setPositions() {
    var width= jQuery(window).width();
    jQuery(".press_li").width(width * 0.75);
}
$(document).ready(function(){setPositions()})
$(window).resize(function(){setPositions()})

看看例子:

使用媒体查询会更好。我必须根据手机屏幕计算li的宽度。媒体查询可以计算li的宽度吗screen@AnkitaAgrawal媒体查询是在CSS上实现的规则,因此您可以简单地应用
width:75%
,而无需使用JS