javascript - Add class to element depending on which side of the screen its on -
i making timeline theme , need have separate class posts on right side of screen , left side of screen. don't see wrong javascript of course not working.
var halfscreenwidth = jquery(document).width() * 0.5; var timelinepost = jquery('.blog .post'); jquery(document).ready( function(){ timelinepost.each( function(){ if( this.position().left < halfscreenwidth ){ jquery(this).addclass('timeline-left'); } else{ jquery(this).addclass('timeline-right'); } }); });
made few modifications @ https://jsfiddle.net/zlv4s0ur/26/ .
if( this.position().left < halfscreenwidth )
should
if( jquery(this).position().left < halfscreenwidth )
Comments
Post a Comment