Lagt inn av: webnorge på: februar 26, 2009
Her er noen smarte, men små kode snutter basert på rammeverket jQuery:
1. Endre skrift størrelsen på siden
$(".fontsize0").click(function() { $("body").css("font-size", "100%"); });
$(".fontsize1").click(function() { $("body").css("font-size", "120%"); });
$(".fontsize2").click(function() { $("body").css("font-size", "140%"); });
<ul>
<li class="fontsize0">Normal</li>
<li class="fontsize1">Medium</li>
<li class="fontsize2">Stor</li>
</ul>
2. Bytte ut <hr /> med <div class=”hr”></div>
$("hr").replaceWith('<div class="hr"></div>');
3. Bruk av ajax
$.ajax({
type: "POST",
url: "php-fil.php",
data: "foo=bar&foobar=orange",
success: function(msg){
alert( "Alt gikk bra " + msg );
}
});
4. Scroll til toppen av siden
$("#top").click(function() { $('html, body').animate({scrollTop:0}, 'slow'); });