jquery

how to fire jquery events after views ajax updated

Submitted by admin on Sun, 10/09/2016 - 13:06

in drupal for compiling some scripts after an ajax loads, you can use the drupal Behaviors.

here is an example of how to use this method:


Drupal.behaviors.myBehavior = {
   attach: function (context, settings) {
      // your jquery or javascript codes goes here ...
   }
};

 

 

jquery countup function for animating number value from zero

Submitted by admin on Mon, 08/01/2016 - 12:28

this function is for animating numbers

here is a simple solution that can be called:


var countup = function(x){
    var $dd = parseInt(x.text());
    jQuery({someValue: 0}).animate({someValue: $dd }, {
	duration: 3000,
	easing:'swing', /* can be anything*/
	step: function() { /* called on every step*/
		x.text(Math.ceil(this.someValue));
	}
    });
}

and demo of more complex and powerful one:

demo

 

 

calling a function on video end ? (HTML5 and mediaelementjs)

Submitted by admin on Sun, 07/24/2016 - 12:20

in html5  you can use this:


$('video').on('ended', function myHandler(e) {
    $(this).addClass('ended');
});

 

and for MediaElement you can use this:

var player = new MediaElementPlayer("video",{
	success: function (mediaElement, domObject) { 
		mediaElement.on('ended', function(e) {
			alert("sometext"); 
        });
	}
});

 

http://mediaelementjs.com/#api

js function for adding a style sheet to an Iframe

Submitted by admin on Mon, 07/18/2016 - 01:51
var addCssToIframe = function() {
  if ($('Iframe').contents().find("head") != undefined) {
    $('Iframe')
      .contents()
      .find("head")
      .append('<link rel="stylesheet" href="../stylesheet.css" type="text/css" />');
    }
};