Little help |
Little help |
![]()
Post
#1
|
|
![]() Mel Blanc was allergic to carrots. ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 6,371 Joined: Aug 2008 Member No: 676,291 ![]() |
Well, I'm going to lighten this place up a bit. See, recently, I made a Tumblr and I used a pretty simple theme that I adjusted to my liking. There's just one thing I want to do it though and that's being able to make all my links fade in and out. Of course, I'm using the jQuery Javascript library to help me out on this but for some reason, I can't seem to get the links to work like I want them to. So, I might need some help.
Come hither. I'm currently using the latest jQuery, jQuery 1.4.1, and I created a function in a separate Javascript file called fade.js. Here's fade.js: CODE jQuery.fn.fade = function(settings) { settings = jQuery.extend({ color: '#A0A0A0', duration: 500 }, settings); return this.each(function() { var original = $(this).css('color'); $(this).mouseover(function() { $(this).animate({ color: settings.color },settings.duration); }); $(this).mouseout(function() { $(this).animate({ color: original },settings.duration); }); }); }; and here's the little Javascript I'm using on my main Tumblr page: CODE <script type="text/javascript"> $(document).ready(function() { $('a').fade({ color: '#F3F1F1', duration: 700 }); }); </script> I've also tried using a class in the Javascript (i.e. - .fade) which was used in some test links but that didn't work either. I don't know if it's a conflict with where I have the files hosted (my own site) and if it should be hosted on Tumblr (which I don't think I can do, or I don't know how) and I noticed Tumblr uses Prototype so I don't know if that would be issue (because I'm pretty sure jQuery and Prototype do not work well together, however, I don't see any Prototype files included on my page). It's been quite annoying and I'd appreciate it if someone could lighten my day with some mystical solution. And with that, I bid adieu. |
|
|
![]() |
![]()
Post
#2
|
|
![]() Treasure Pleasure ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Head Staff Posts: 11,193 Joined: Oct 2005 Member No: 281,127 ![]() |
There's probably a variable that both scripts are sharing and are conflicting with each other. Try this jQuery workaround.
|
|
|
![]()
Post
#3
|
|
![]() Mel Blanc was allergic to carrots. ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 6,371 Joined: Aug 2008 Member No: 676,291 ![]() |
There's probably a variable that both scripts are sharing and are conflicting with each other. Try this jQuery workaround. Aw, shoot. That didn't work either. ![]() Who makes Tumblr themes here on CB? |
|
|
![]()
Post
#4
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Administrator Posts: 8,629 Joined: Jan 2007 Member No: 498,468 ![]() |
^TJ and Gabrielle.
![]() |
|
|
![]()
Post
#5
|
|
Senior Member ![]() ![]() ![]() ![]() ![]() ![]() Group: Member Posts: 1,237 Joined: May 2008 Member No: 648,123 ![]() |
You shouldn't have to use the noConflict() function, since you're using a theme that doesn't use any of Tumblr's original code (all of the special tags are taken care of server side). You're probably having a problem because you're not declaring the plugin as an extension of jQuery.
Try something like this: CODE (function($) { $.fn.fade = function(settings) { settings = $.extend({ color: '#A0A0A0', duration: 500 }, settings); return this.each(function() { var original = $(this).css('color'); $(this).hover( function() { $(this).stop().animate({ color: settings.color }, settings.duration) }, function() { $(this).stop().animate({ color: original }, settings.duration) } ) }) }; $(function() { $('a').fade({ color: '#F3F1F1', duration: 700 }) } })(jQuery); You were using $(this) in the plugin, which is a shortcut for jQuery(this). To use it as $(this), you need to define the $ character to be used with jQuery (like above). Also, notice the change I made to the plugin return. jQuery's .hover() is easier to use than .mouseover() and .mouseout(). It takes two functions, separated by commas. The first function is when you hover over an element, and the second function is when you leave the element. I also added in .stop() before each animation. That stops the current animation if you hover over another element so the animation queue doesn't build up and keep firing. You can use CODE $(function() { // do stuff after the document loads }) as a shortcut in place of CODE $(document).ready(function() { // do stuff after the document loads }) I'd also suggest using a packed version of jQuery; unpacked is enormous and a burden on both your server and people trying to view the page. Google has a packed, gzipped and cached version of jQuery 1.4.1 here. If someone was on another site that used the Google cached version, then it'll already be loaded when they visit your Tumblr. |
|
|
![]()
Post
#6
|
|
![]() Mel Blanc was allergic to carrots. ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 6,371 Joined: Aug 2008 Member No: 676,291 ![]() |
^That didn't work, either. Does Tumblr even allow/enable jQuery to be used on there? Because I saw another theme (Fluid) that uses jQuery to supposedly load more posts but that doesn't seem to work either, for me at least.
|
|
|
![]()
Post
#7
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Staff Alumni Posts: 7,063 Joined: Jul 2008 Member No: 670,288 ![]() |
^TJ and Gabrielle. ![]() LOL, I've never made a Tumblr theme in my life Nat. :P |
|
|
![]()
Post
#8
|
|
Senior Member ![]() ![]() ![]() ![]() ![]() ![]() Group: Member Posts: 1,237 Joined: May 2008 Member No: 648,123 ![]() |
^That didn't work, either. Does Tumblr even allow/enable jQuery to be used on there? Because I saw another theme (Fluid) that uses jQuery to supposedly load more posts but that doesn't seem to work either, for me at least. I've never had a problem using jQuery with Tumblr. It's just a JavaScript library, so you could put the entire thing between <script> tags if you wanted. Color transitions aren't natively supported by jQuery; you need to either define values or get a plugin that does it for you. |
|
|
![]()
Post
#9
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Administrator Posts: 8,629 Joined: Jan 2007 Member No: 498,468 ![]() |
http://i18.photobucket.com/albums/b127/gut...zibit_AG036.jpg LOL, I've never made a Tumblr theme in my life Nat. :P Haha oh whoops. I thought you did. Imy, btw |
|
|
![]() ![]() |