I found that the $(window).resize() will be triggered when you scroll up/down the website on a mobile device. To prevent this happens, we could add a checking on the screen width.
var width = $(window).width();
$(window).resize(function(){
if ($(window).width() != width) {
// Only action on screen width change
width = $(window).width();
}
});
I am working on a Foundation 5 website and i would like to detect the breakpoint change when the user resize the browser window. Here is a workaround found in the Foundation Forum.
1. Add the following piece of HTML to your website. Since i am working with Drupal 7 with the Foundaiton 5 theme, i just add it to the page.tpl.php in the subtheme.
The <img> allows us to show an image in different size on the browser by setting its width and height. We could get the displayed image width and height in jQuery as follow.
However, sometimes we would like to get the actual image width and height of the source image. The following solution is what i found in StackOverflow.
$("<img>") // Create a new <img>
.attr("src", $("#img-tag-id").attr("src")) // Copy the src attr from the target <img>
.load(function() {
// Print to console
console.log("Width: " + this.width);
console.log("Height: " + this.height);
});
How about if your target elements is dynamically added to the DOM? In that case, the event listener would not work for the newly inserted inner elements. A work around is attached the event listener to the parent element instead. Here is another example for the delegated event implementation of TouchSwipe. Continue reading TouchSwipe – Implement delegated swipe event for inner elements→
Recently doing some proof of concept on using jQuery SnapScroll. The demo worked without any problem but when i implemented it, i couldn’t make my div taking 100% height of the view port. Finally i figured out that the failure was caused by the HTML5 Doctype declaration on the index.html.