Home › Forums › JavaScript › Can’t make work 2 jQuery plugins at the same time!
- This topic is empty.
-
AuthorPosts
-
July 12, 2010 at 12:12 pm #29603
shiolo
MemberHi, I’m learning jQuery and I was trying to use two jQuery plugins in a site, but couln’t make them work both. I can use one, or the other.
I wanted to add to my site the MagicLine Navigation (https://css-tricks.com/examples/MagicLine/) to my site and an accordion widget which I took from the jQuery UI site (http://jqueryui.com/demos/accordion/). I first set the magicline and it worked perfectly. Then I add the accordion to the site, and it didn’t worked, so I thought I was setting the accordion in a wrong way, but when I removed the MagicLine, the accordion worked well.
As I said, I am just starting, I don’t know what I’m doing wrong…I tried to combine the two js files (the accordion and magicline) into one but I works only the one which is first…What am I missing???
Thanks!!
July 19, 2010 at 5:26 pm #80007shiolo
MemberPLEASE SOMEONE HELP ME!!
July 19, 2010 at 6:19 pm #80024dcp3450
Participantcan you post a link to your site and/or your site code?
July 19, 2010 at 6:32 pm #80026shiolo
MemberThis is the code of the html file:
Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Connection Unlimited</title>
<link href="main.css" rel="stylesheet" type="text/css" />
<link href="jquery-ui-1.8.2.custom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type=’text/javascript’ src=’js/magicLine.js’></script>
<script type="text/javascript" src="js/jquery-ui-1.8.2.custom.min.js"></script>
<script type="text/javascript">
$(function() {
$("#accordion").accordion();
});
</script></head>
<body>
<div id="container">
<div id="smallMenu">
<ul>
<li><a href="main.html">LOGIN</a></li>
<li><a href="main.html">CATALOG</a></li>
<li><a href="main.html">LINKS</a></li>
</ul>
</div>
<div id="header">
<div id="logo">
<a href="main.html">Logo</a>
</div>
<div id="mainMenu">
<ul id="example-one">
<li><a href="main.html">About</a></li>
<li class="current_page_item"><a href="main.html">Services</a></li>
<li><a href="main.html">Contact</a></li>
</ul>
</div>
</div>
<br class="clear" />
<div id="content">
<div id="content-left">
<h1 class="title">Distributors</h1>
<p>"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<br /><!–aca empieza el acordion para el content left–>
<div id="accordion">
<h3><a href="#">Section 1</a></h3>
<div>
<p>
Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
</p>
</div>
<h3><a href="#">Section 2</a></h3>
<div>
<p>
Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet
purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor
velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In
suscipit faucibus urna.
</p>
</div>
<h3><a href="#">Section 3</a></h3>
<div>
<p>
Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis.
Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero
ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis
lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui.
</p>
<ul>
<li>List item one</li>
<li>List item two</li>
<li>List item three</li>
</ul>
</div>
<h3><a href="#">Section 4</a></h3>
<div>
<p>
Cras dictum. Pellentesque habitant morbi tristique senectus et netus
et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in
faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia
mauris vel est.
</p>
<p>
Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus.
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
inceptos himenaeos.
</p>
</div>
</div><!–aca termina el acordion para el content left–>
</div>
<div id="content-right">
<h1 class="title">Manufacturers</h1>
<p>"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p></div>
</div>
<br class="clear" />
<div id="footer">
<ul>
<li><a href="main.html">login</a></li>
<li><a href="main.html">catalog</a></li>
<li><a href="main.html">contact</a></li>
</ul>
</div>
</div></body>
</html>Anything you need just ask me!
Thanks for the helpJuly 19, 2010 at 7:02 pm #80028dcp3450
Participantits something in <script type=’text/javascript’ src=’js/magicLine.js’></script>
I created my own to see what was going on. Once I added that file accordion quit working.
However, when i placed accordion and the magicline in the same script they both worked (note- I have this in the header not a different file):
Code:<script>
$(function()
{
$("#accordion").accordion();var $el, leftPos, newWidth,
$mainNav = $("#example-one"),
$mainNav2 = $("#example-two");/*
EXAMPLE ONE
*/
$mainNav.append("<li id=’magic-line’></li>");var $magicLine = $("#magic-line");
$magicLine
.width($(".current_page_item").width())
.css("left", $(".current_page_item a").position().left)
.data("origLeft", $magicLine.position().left)
.data("origWidth", $magicLine.width());$("#example-one li").find("a").hover(function() {
$el = $(this);
leftPos = $el.position().left;
newWidth = $el.parent().width();$magicLine.stop().animate({
left: leftPos,
width: newWidth
});
}, function() {
$magicLine.stop().animate({
left: $magicLine.data("origLeft"),
width: $magicLine.data("origWidth")
});
});/*
EXAMPLE TWO
*/
$mainNav2.append("<li id=’magic-line-two’></li>");var $magicLineTwo = $("#magic-line-two");
$magicLineTwo
.width($(".current_page_item_two").width())
.height($mainNav2.height())
.css("left", $(".current_page_item_two a").position().left)
.data("origLeft", $(".current_page_item_two a").position().left)
.data("origWidth", $magicLineTwo.width())
.data("origColor", $(".current_page_item_two a").attr("rel"));$("#example-two li").find("a").hover(function() {
$el = $(this);
leftPos = $el.position().left;
newWidth = $el.parent().width();
$magicLineTwo.stop().animate({
left: leftPos,
width: newWidth,
backgroundColor: $el.attr("rel")
})
}, function() {
$magicLineTwo.stop().animate({
left: $magicLineTwo.data("origLeft"),
width: $magicLineTwo.data("origWidth"),
backgroundColor: $magicLineTwo.data("origColor")
});
});
});
</script>July 19, 2010 at 7:23 pm #80033shiolo
Membersory but i dind’t understand your answer, you combined both js files into one? one right after the other one??
then you just <script type="text/javascript" src="…js"></script> and it worked??July 19, 2010 at 7:48 pm #80034shiolo
MemberMake it work how you told me! I changed the code of the magicLine.js with the code you posted. I would like to know WHY it didn’t worked previously. Someone suggested that both files where trying to use the same function name. As I said I’m a newbie so can someone explain me what happened??
Thanks!!July 30, 2010 at 1:21 am #80691natedigby21
Member"dcp3450" wrote:its something in <script type=’text/javascript’ src=’js/magicLine.js’></script>I created my own to see what was going on. Once I added that file accordion quit working.
However, when i placed accordion and the magicline in the same script they both worked (note- I have this in the header not a different file):
Code:<script>
$(function()
{
$("#accordion").accordion();var $el, leftPos, newWidth,
$mainNav = $("#example-one"),
$mainNav2 = $("#example-two");/*
EXAMPLE ONE
*/
$mainNav.append("<li id=’magic-line’></li>");var $magicLine = $("#magic-line");
$magicLine
.width($(".current_page_item").width())
.css("left", $(".current_page_item a").position().left)
.data("origLeft", $magicLine.position().left)
.data("origWidth", $magicLine.width());$("#example-one li").find("a").hover(function() {
$el = $(this);
leftPos = $el.position().left;
newWidth = $el.parent().width();$magicLine.stop().animate({
left: leftPos,
width: newWidth
});
}, function() {
$magicLine.stop().animate({
left: $magicLine.data("origLeft"),
width: $magicLine.data("origWidth")
});
});/*
EXAMPLE TWO
*/
$mainNav2.append("<li id=’magic-line-two’></li>");var $magicLineTwo = $("#magic-line-two");
$magicLineTwo
.width($(".current_page_item_two").width())
.height($mainNav2.height())
.css("left", $(".current_page_item_two a").position().left)
.data("origLeft", $(".current_page_item_two a").position().left)
.data("origWidth", $magicLineTwo.width())
.data("origColor", $(".current_page_item_two a").attr("rel"));$("#example-two li").find("a").hover(function() {
$el = $(this);
leftPos = $el.position().left;
newWidth = $el.parent().width();
$magicLineTwo.stop().animate({
left: leftPos,
width: newWidth,
backgroundColor: $el.attr("rel")
})
}, function() {
$magicLineTwo.stop().animate({
left: $magicLineTwo.data("origLeft"),
width: $magicLineTwo.data("origWidth"),
backgroundColor: $magicLineTwo.data("origColor")
});
});
});
</script>Thank you so much for this reply! This really helped me a lot!
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.