html - Change images on hover with AngularJS -
okay, need change images on hover in angular app. however, due peculiarities of site, wasn't feasible change images on hover via css [without ton of work], have been best way, realize.
so instead, i'm using ng-mouseenter , ng-mouseleave change images on hover.
landing.jade
img.share-button(src='images/btn_share.png', ng-click='dropdownshareicons()') img.share-icon-top(src='{{ shareicons[0].orig }}', data-id='0', ng-mouseenter='colorizeicons($event)', ng-mouseleave='decolorizeicons($event)') img.share-icon-top(src='{{ shareicons[1].orig }}', data-id='1', ng-mouseenter='colorizeicons($event)', ng-mouseleave='decolorizeicons($event)') img.share-icon-top(src='{{ shareicons[2].orig }}', data-id='2', ng-mouseenter='colorizeicons($event)', ng-mouseleave='decolorizeicons($event)')
then in controller have object contains paths images, , functions switch images on hover.
landing.js
$scope.shareicons = [ {orig: 'images/follow_weibo_grey.png', hover: 'images/follow_weibo_colored.png'}, {orig: 'images/follow_wechat_grey.png', hover: 'images/follow_wechat_colored.png'}, {orig: 'images/follow_youku_grey.png', hover: 'images/follow_youku_colored.png'}, ] $scope.colorizeicons = function($event) { $event.target.src = $scope.shareicons[$event.target.dataset.id].hover; } $scope.decolorizeicons = function($event) { $event.target.src = $scope.shareicons[$event.target.dataset.id].orig; }
this works fine , on local environment, on production server veeeerrrrry slow. like, 2-3 seconds switch images.
so question - there easy way fix this? either within angular or workaround/hack. doesnt matter long image switch time sped bit. or going continue slow long i'm switching images via js this? ideally, avoid rewriting using css.
thanks in advance.
hey bro had same problem, , think of doing preloading images. helped alot. add small piece of js code loads asynchronously @ beginning of document. example:
var images = new array() function preload() { (i = 0; < preload.arguments.length; i++) { images[i] = new image() images[i].src = preload.arguments[i] } } preload( // (i = 0; < $scope.members.length; ++){ // return members[i].source + ","; // } "http://ramiawar.co/pages/speakerspage/pages/team/assets/images/image1.1.jpg", "http://ramiawar.co/pages/speakerspage/pages/team/assets/images/image2.1.jpg", "http://ramiawar.co/pages/speakerspage/pages/team/assets/images/image3.1.jpg", "http://ramiawar.co/pages/speakerspage/pages/team/assets/images/image4.1.jpg", "http://ramiawar.co/pages/speakerspage/pages/team/assets/images/image5.1.jpg", "http://ramiawar.co/pages/speakerspage/pages/team/assets/images/image6.1.jpg" )
Comments
Post a Comment