Skip to content

Instantly share code, notes, and snippets.

@gillesv
gillesv / gist:4277801
Created December 13, 2012 16:43
2 JQuery scrolling methods I use. Scroll to a position in pixels, or scroll to an element. Duration of scrolling animation is calculated dynamically based on how many pixels the viewport has to travel. Fiddle with the math on line 5 to tweak the speed to your liking.
// scrolling methods: scroll to pixels
function scrollViewTo(target, callback) {
var duration, pos;
pos = $body.scrollTop();
duration = ((Math.abs(pos - target) / 1000) * 1000);
$("html:not(:animated),body:not(:animated)").animate({scrollTop: target + 'px'}, duration, callback);
}
// scroll to element
<!-- Using conditional comments, we hide the mediaquery-laden styles from IE8 and below... -->
<!--[if ! lte IE 8]><!-->
<link rel="stylesheet" href="css/style.css">
<![endif]-->
<!-- ... and instead serve them the 'collapsed' styles as a separate stylesheet... -->
<!--[if lte IE 8]>
<link rel="stylesheet" href="css/ie.css">
/*
ie.less
*/
@import "libs/reset.less";
@import "mediaqueries/global.less";
@import "mediaqueries/mobile.less";
@import "mediaqueries/tablet.less";
@import "mediaqueries/desktop.less";
/*
style.less
*/
@import "libs/reset.less";
@import "mediaqueries/global.less";
@import "mediaqueries/mobile.less";
@import "mediaqueries/tablet.less";
@import "mediaqueries/desktop.less";
.mqMobile(@param:"bogus"){
/* CSS code goes here */
}
@media only screen and (min-width: 480px) {}
@media only screen and (min-width: 768px) {}
@media only screen and (min-width: 992px) {}
etc...
@import "libs/reset.less";
@import "mediaqueries/global.less";
@import "mediaqueries/mobile.less";
@import "mediaqueries/tablet.less";
@import "mediaqueries/desktop.less";
@import "mediaqueries/huge.less";
package
{
import be.proximity.framework.Framework;
import be.proximity.framework.config.Config;
import be.proximity.framework.net.VarSources;
/**
* By extending from Framework the Config class is automatically set up correctly.
*/
public class QuerystringsDemos extends Framework
<!-- vanilla swfobject -->
<script type="text/javascript" src="assets/js/swfobject.js"></script>
<!-- flash embedding and other tiny javascript -->
<script type="text/javascript">
//<![CDATA[
var flashvars = { config: "default", someParameter: "woot, it works!"};
var params = { allowFullScreen : true };
var attributes = { id: "flash" };
package {
import be.proximity.framework.Framework;
import be.proximity.framework.config.Config;
import be.proximity.framework.net.VarSources;
import flash.display.Sprite;
/**
* By extending from Framework the Config class is automatically set up correctly.
*/