Jump to content
  • 0

конфликт jquery


maritca
 Share

Question

Подскажите, пожалуйста, как грамотно совместить два скрипта?

Первый (подключается через отдельный файл):

$(document).ready(function() {
$('#menu > li > ul' )
.hide()
.click(function(event) {
event.stopPropagation();
});

$('#menu > li').toggle(function() {
$(this).find('ul').slideDown();
}, function() {
$(this).find('ul').slideUp();
});
});

Второй (прописан в body):


<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function() {
jQuery('#sigplus_catalogos_regalo').imageSlider({
itemCount: 4,
showButtons: true,
showLinks: true,
showPageCounter: true,
alignment: 'center',
orientation: 'horizontal',
navigation: 'bottom',
firstText: 'вперед',
prevText: 'назад',
nextText: 'след',
lastText: 'пред',
pageText: '%1$d of %2$d' }); });

window.addEvent('load', function() {
var imgs = [];
<?php $i = 0; while ($i <= $iNumFiles-1) { echo ("imgs.push({file: '$aFileList[$i]', title: '', desc: '', url: ''});\r\n "); $i++; }?>
var myshow = new Slideshow('slideshow', {
type: 'combo',
externals: 0,
showTitleCaption: 0,
captionHeight: 45,
width: 959,
height: 274,
pan: 50,
zoom: 20,
loadingDiv: 0,
resize: true,
duration: [5000, 7000],
transition: Fx.Transitions.Sine.easeOut,
images: imgs,
path: 'content/logoimg/<? echo($part); ?>/' });
myshow.caps.h2.setStyles({color: '#fff', fontSize: '13px'});
myshow.caps.p.setStyles({color: '#ccc', fontSize: '11px'}); });
</script>

По отдельности оба работают. Когда подключаются одновременно, в консоли выползает ошибка:

Uncaught TypeError: Cannot call method 'hide' of null (первый скрипт)

Edited by maritca
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

может все таки не стоит использовать одновременно и jquery и mootools ?

если уж это и делать то только в случаях когда по другому не решить вопрос.

а вообще попробуйте в первом скрипте заменить вызовы $ на jQuery, и объединить скрипты в один:


<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function() {
jQuery('#menu > li > ul' )
.hide()
.click(function(event) {
event.stopPropagation();
});

jQuery('#menu > li').toggle(function() {
jQuery(this).find('ul').slideDown();
}, function() {
jQuery(this).find('ul').slideUp();
});



jQuery('#sigplus_catalogos_regalo').imageSlider({
itemCount: 4,
showButtons: true,
showLinks: true,
showPageCounter: true,
alignment: 'center',
orientation: 'horizontal',
navigation: 'bottom',
firstText: 'вперед',
prevText: 'назад',
nextText: 'след',
lastText: 'пред',
pageText: '%1$d of %2$d' }); });
window.addEvent('load', function() {
var imgs = [];
<?php $i = 0; while ($i <= $iNumFiles-1) { echo ("imgs.push({file: '$aFileList[$i]', title: '', desc: '', url: ''});\r\n "); $i++; }?>
var myshow = new Slideshow('slideshow', {
type: 'combo',
externals: 0,
showTitleCaption: 0,
captionHeight: 45,
width: 959,
height: 274,
pan: 50,
zoom: 20,
loadingDiv: 0,
resize: true,
duration: [5000, 7000],
transition: Fx.Transitions.Sine.easeOut,
images: imgs,
path: 'content/logoimg/<? echo($part); ?>/' });
myshow.caps.h2.setStyles({color: '#fff', fontSize: '13px'});
myshow.caps.p.setStyles({color: '#ccc', fontSize: '11px'}); });
</script>

Edited by wwt
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy