on load and resize jquery both
You can use the $(document).ready() function to execute code when the page is loaded and the $(window).resize() function to execute code when the window is resized. Here's an example:
$(document).ready(function() {
// code to execute when the page is loaded
});
$(window).resize(function() {
// code to execute when the window is resized
});
You can put any code you want inside these functions. For example, if you want to change the background color of a div when the page is loaded and when the window is resized, you can do this:
$(document).ready(function() {
$('#mydiv').css('background-color', 'red');
});
$(window).resize(function() {
$('#mydiv').css('background-color', 'blue');
});
This will set the background color of the #mydiv element to red when the page is loaded and to blue when the window is resized.
原文地址: http://www.cveoy.top/t/topic/b7TU 著作权归作者所有。请勿转载和采集!