admin管理员组文章数量:1420135
Could you please help me with a bit of a jquery script please. I am trying to achieve something by using a bit of a jquery script (and it's working great) but I need this to work desktop-only, it has to be disabled on tablets and mobiles.
Script I'm using is
jQuery(document).ready(function($) {
var max = 0;
$(".sameheight .x-column").each(function(index, el) {
if( $(this).height() > max ){
max = $(this).height();
}
});
$(".sameheight .x-column").css('height', max);
});
Can someone help me please?
Thank you
Could you please help me with a bit of a jquery script please. I am trying to achieve something by using a bit of a jquery script (and it's working great) but I need this to work desktop-only, it has to be disabled on tablets and mobiles.
Script I'm using is
jQuery(document).ready(function($) {
var max = 0;
$(".sameheight .x-column").each(function(index, el) {
if( $(this).height() > max ){
max = $(this).height();
}
});
$(".sameheight .x-column").css('height', max);
});
Can someone help me please?
Thank you
Share Improve this question asked Mar 14, 2017 at 10:47 eugenepeugenep 311 silver badge2 bronze badges 1- Possible duplicate of Auto detect mobile browser (via user-agent?) – Stefano Zanini Commented Mar 14, 2017 at 10:52
2 Answers
Reset to default 4You can check the body width to be above 1024px and then run the code.
Example below.
var width = $("body").width();
console.log(width);
if (width > 1024) {
alert("Over 1024;")
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
</body>
If i understand you correctly pls try this
NB:- Pls try the snippet in fullscreen mode;
function resizeColumnOnDesktop() {
var width = $("body").width();
if (width > 1024) {
var max = 0;
$(".sameheight .x-column").each(function(index, el) {
if ($(this).height() > max) {
max = $(this).height();
}
});
$(".sameheight .x-column").css('height', max);
}
};
$(window).on("load resize", function(e) {
resizeColumnOnDesktop()
});
.x-column {
background: #EEE;
width: 20%;
float: left;
margin: 5%;
padding :10px;
text-align: justify;
border:1px solid #000;
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="sameheight">
<div class="x-column">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
<div class="x-column">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer
took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
<div class="x-column">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to </div>
<div class="x-column">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
<div class="x-column">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer
took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div><div class="x-column">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text </div>
</div>
本文标签: javascriptjquery script to work desktoponlyStack Overflow
版权声明:本文标题:javascript - jquery script to work desktop-only - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745318532a2653267.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论