drag multiple elements at the same time to the drop area - php

I'm new to jQueryUI and I'm not able to drag multiple <li> elements to the drop area. However I managed to drag one and drop it on the drop area. Please can anyone help me with this.
JavaScript
$(function() {
$trash= $( "#trash" );
$("a", ".polaroids").draggable({
zIndex: 999,
revert: "invalid" ,
helper: function(){
$copy = $(this).clone();
return $copy;},
appendTo: 'body',
scroll: false
});
$("a", ".polaroids").selectable();
$trash.droppable({
accept: ".polaroids a",
activeClass: "custom-state-active",
drop: function( event, ui ) {
$(this).append(ui.draggable);
}
});
});
Here is the <div> in which the <li> elements are dragged but one by one
<div class="st_view_container">
<div class="st_view">
<?php
foreach($gpID as $k => $v) {
?>
<div id="stv_content_<?php echo $v;?>" class="st_tab_view st_first_tab_view">
<ul class="polaroids" id ="polaroids">
<?php
$sql2=mysql_query("select * from user_group WHERE group_id='$v' AND user_id=3");
$i=1;
while($row=mysql_fetch_array($sql2)) {
$memid=$row['member_id'];
$sql1=mysql_query("select * from users_profile WHERE uid='$memid'");
while($row1=mysql_fetch_array($sql1)) {
$ufname=$row1['fname'];
$ulname=$row1['lname'];
$upic=$row1['profile_pic'];
?>
<li>
<a href="#" title="<?php echo $ufname; ?>">
<img src="../<?php echo $upic; ?>" rel="<?php echo $row1['uid']?>" width="65px" height="65px" />
</a>
</li>
<?php
if($i%6==0) {;}
$i++;
}
?>
</ul>
</div>
<?php } ?>
</div> <!-- /.st_view -->
</div> <!-- /.st_view_container -->
and here is the <div> in which i want the multiple elements to be dropped, but not one by one.
<div id="trash" style="width:200px; height:200px; border:1px solid;">
<h4 class="ui-widget-header"><span class="ui-icon ui-icon-trash">Trash</span> Trash</h4>
</div>

Here is a demo based on some research…
Is it possible to link two jquery.ui draggables together?
grouping draggable objects with jquery-ui draggable
Can't drop jquery ui helper on droppable
How to reimplement jQuery's default helper in a custom helper
and me playing with the jQueryUI droppable photo manager demo which is what you are using as a template.
Functionality includes single click and drag (as is the default behaviour) or use Ctrl+left click to select multiple items and then drag. The drag helper function is used to select all the items with class="selected" and the drop function is customised to extract the img elements from the container the drag helper added them to. The other function simple enables the Ctrl+click behaviour.
The following code is duplicated below from the demo but does require jQuery, jQueryUI and one of the jQueryUI themes.
HTML
<ul id="draggable">
<li><img src="nature-q-c-50-50-1.jpg" alt="" /></li>
<li><img src="nature-q-c-50-50-2.jpg" alt="" /></li>
<li><img src="nature-q-c-50-50-3.jpg" alt="" /></li>
<li><img src="nature-q-c-50-50-4.jpg" alt="" /></li>
<li><img src="nature-q-c-50-50-5.jpg" alt="" /></li>
<li><img src="nature-q-c-50-50-6.jpg" alt="" /></li>
</ul>
<div id="trash">
<h4 class="ui-widget-header">Trash<span class="ui-icon ui-icon-trash"></span></h4>
</div>
CSS
body {
font-family:"Trebuchet MS";
}
#draggable {
margin:0;
padding:10px;
width:300px;
list-style-type:none;
background-color:#000;
}
li {
display:inline;
}
img {
border:5px solid white;
}
.image-group img {
margin-right:5px;
}
#trash {
margin-top:10px;
width:200px;
height:200px;
border:1px dotted #000;
}
.selected {
border-color:#aed0ea
}
#trash h4 {
margin:0;
padding:0 5px;
}
.ui-icon {
display:inline-block;
}
JavaScript
$('#draggable li').draggable({
revertDuration:100,
helper:function() {
var selected = $('#draggable img.selected');
if (selected.length === 0) {
selected = $('img', $(this)).addClass('selected');
}
console.log('selected', selected);
var container = $('<div class="image-group"/>');
container.append(selected.clone());
console.log('container', container);
return container;
},
cursorAt:{ left:25,top:25 }
});
$('#trash').droppable({
drop: function(event, ui) {
var newItems = $(ui.helper).find('img').clone(false)
.removeClass('selected');
$(this).append(newItems);
console.log('ui.draggable', ui.draggable);
$('#draggable img.selected').parent().remove();
}
});
$('#draggable li').click(function(event) {
if (event.ctrlKey) {
$('img', $(this)).toggleClass('selected');
}
});

Related

jQuery Splide, responsive height based on image

We got this slide based on Splide, used as article's photo slider, with attached second instance that act as a thumbnail paginator.
At the moment, it doesn't take care of the height of the pics, but just use the height of the taller image, making the thumbnails remain down when a 16/9 image is displayed, leaving a big white space unused.
Even if it is an huge layout swift, we need thumbnails staying glued to the bottom of the image, sliding up or down when an image change, can we achieve this situation?
Currently, my code is:
<!-- Slideshow container -->
<section id="main-carousel" class="splide" role="group" style="margin-top: 30px" >
<div class="splide__track">
<ul class="splide__list">
<?php
$i = 0;
foreach(get_field('gallery') as $image ) {
if ($i == 0) { $active = 'active'; } else { $active = '';}
echo '<li class="splide__slide" data-splide-interval="3000">';
echo '<div class="splide__slide__container" style="max-height: fit-content>';
echo '<a href="' . $image .'" data-lightbox="image-' . ($i + 1) . '">';
echo '<img src="' . $image . '" style="width:100%" />';
echo '</a>';
echo '</div>';
echo '</li>';
$i++;
}
?>
</ul>
</div>
<br class="clear" />
</section>
<script>
var splide = new Splide( '.splide' );
splide.mount();
</script>
<section id="thumbnail-carousel" class="splide" style="margin-top: 10px; height: auto">
<div class="splide__track">
<ul class="splide__list" style="height:auto!important">
<?php
$i = 0;
foreach(get_field('gallery') as $image ) {
if ($i == 0) { $active = 'active'; } else { $active = '';}
echo '<li class="splide__slide" style="height:auto or 100%">';
echo '<img src="' . $image . '" style="width:100%; height: auto or 100%" />';
echo '</li>';
$i++;
}
?>
</ul>
</div>
</section>
<style>
.splide__list {
align-items: flex-start!important;
}
.clear { clear: both; }
</style>
<script>
document.addEventListener( 'DOMContentLoaded', function () {
var main = new Splide( '#main-carousel', {
type : 'loop',
rewind : true,
pagination: false,
arrows : false,
autoHeight: true,
autoWidth: true,
//autoplay : true,
autoStart : true,
lazyLoad: true,
perPage : 1,
perMove: 1,
autoScroll: {
speed: 1,
},
} );
var thumbnails = new Splide( '#thumbnail-carousel', {
fixedWidth : 100,
fixedHeight : 58,
gap : 8,
rewind : true,
pagination : false,
isNavigation: true,
//autoHeight: true,
breakpoints : {
600: {
fixedWidth : 60,
fixedHeight: 44,
},
},
} );
main.sync( thumbnails );
main.mount( window.splide.Extensions );
thumbnails.mount();
} );
</script>
<?php } ?>
You will need to dynamically change the slide height using the height of the next image before the carousel moves to keep the thumbnails 'glued' to the slider.
Use the Splide#on() method to listen to the ready event (to apply the first slide height) and the move event (to apply the slide height when the carousel moves).
To know which slide the carousel is moving to, use the instance property index. To change the slide height, use the property options.
var main = new Splide('#main-carousel');
main.on('ready', function() {
setHeightCarousel(0); // index = 0
})
main.mount();
main.on('move', function() {
const currentIndex = main.index;
setHeightCarousel(currentIndex);
})
And here's how setHeightCarousel(index) could look like. Note I added the class splide__img in the HTML on each <img> tag to target them.
function setHeightCarousel(index) {
const image = document.querySelectorAll('.splide__img')[index];
let imgHeight;
if (image.complete) {
imgHeight = image.naturalHeight;
main.options = {
height: imgHeight + 'px'
}
} else {
image.addEventListener('load', function() {
imgHeight = this.naturalHeight;
main.options = {
height: imgHeight + 'px'
}
})
}
}
Because the ready event fires before the image is loaded the function first checks whether the image is loaded, and if not adds a load event listener. A callback or promise is purposefully avoided here, but can be used to improve the code depending on the implementation.
The naturalHeight property is used to get the intrinsic height of the image, in the presumption you might want to (down)scale the image first.
Here's a working example in a JSFiddle using Splide V4.1.4.
Or view it in a snippet:
document.addEventListener('DOMContentLoaded', function() {
var main = new Splide('#main-carousel', {
type: 'fade',
rewind: true,
pagination: false,
arrows: false,
lazyLoad: 'sequential'
})
var thumbnails = new Splide('#thumbnail-carousel', {
fixedWidth: 100,
fixedHeight: 60,
gap: 10,
rewind: true,
pagination: false,
isNavigation: true,
breakpoints: {
600: {
fixedWidth: 60,
fixedHeight: 44,
},
}
})
main.on('ready', function() {
setHeightCarousel(0);
})
main.sync(thumbnails);
main.mount();
thumbnails.mount();
main.on('move', function() {
const currentIndex = main.index;
setHeightCarousel(currentIndex);
})
function setHeightCarousel(index) {
const image = document.querySelectorAll('.splide__img')[index];
let imgHeight;
if (image.complete) {
imgHeight = image.naturalHeight;
main.options = {
height: imgHeight + 'px'
}
} else {
image.addEventListener('load', function() {
imgHeight = this.naturalHeight;
main.options = {
height: imgHeight + 'px'
}
})
}
}
})
.container {
margin: 1rem 1rem;
}
#thumbnail-carousel .splide__track .splide__list .splide__slide img {
width: 100%;
height: 100%;
object-fit: cover;
}
/* Centers the image */
/*
.splide__slide img {
width: 100%;
height: 100%;
object-fit: scale-down;
}
*/
<script src="https://cdn.jsdelivr.net/npm/#splidejs/splide#4.1.4/dist/js/splide.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/#splidejs/splide#4.1.4/dist/css/splide.min.css">
<div class="container">
<section id="main-carousel" class="splide" aria-label="Beautiful Images">
<div class="splide__track">
<ul class="splide__list">
<li class="splide__slide">
<div class="splide__slide__container">
<img data-splide-lazy="https://via.placeholder.com/250x140" alt="" class="splide__img">
</div>
</li>
<li class="splide__slide">
<div class="splide__slide__container">
<img data-splide-lazy="https://via.placeholder.com/140x250" alt="" class="splide__img">
</div>
</li>
<li class="splide__slide">
<div class="splide__slide__container">
<img data-splide-lazy="https://via.placeholder.com/250x140" alt="" class="splide__img">
</div>
</li>
</ul>
</div>
</section>
<section id="thumbnail-carousel" class="splide">
<div class="splide__track">
<ul class="splide__list">
<li class="splide__slide">
<img src="https://via.placeholder.com/250x140" alt="">
</li>
<li class="splide__slide">
<img src="https://via.placeholder.com/140x250" alt="">
</li>
<li class="splide__slide">
<img src="https://via.placeholder.com/250x140" alt="">
</li>
</ul>
</div>
</section>
</div>
A few notes.
To make lazy load work, the img element in the slide must have the data-splide-lazy attribute that indicates the path or URL to the source file.
By changing the height of the slider and therefore the position of the thumbnails you are shifting the layout. This is generally considered poor UX and can be measured using the Cumulative Layout Shift. Alternatives are to position the thumbnails on top or aside the main carousel, or by centering the 16:9 image (leaving white-space around it versus just below it).

How to change the alignment on materialize

i am using the materialize framework for my front-end design but when its load initially all looks good but when i return to index there comes the problem with the alignment when i clear the cookies it looks good
This is how its looking
This is the orginal Expected Output.
Can anyone help to resolve the Issuie
<!DOCTYPE html>
<html>
<head> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="<?php echo base_url('assets/') ?>css/materialize.css" rel="stylesheet">
<link href="<?php echo base_url('assets/') ?>css/slippry.css" rel="stylesheet">
<link rel="shortcut icon" href="<?php echo base_url('assets/images/logo/favicon.ico'); ?>" type="image/x-icon">
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="<?php echo base_url('assets/'); ?>js/materialize.js"></script>
<title>Tolle Exam No.1 Exam Platform for Nursing Exam | RAILWAY Exam</title>
</head>
<style type="text/css" media="screen">
.morecontent span {
display: none;
}
.morelink {
display: block;
}
nav ul li:hover {
background-color: #00ffbf;
}
.input-field input:focus + label {
color: orange !important;
}
.input-field input:focus {
border-bottom: 1px solid orange !important;
box-shadow: 0 1px 0 0 orange !important
}
#viewMore{
display: none;
}
.dropdown-content {
background-color: #FFFFFF;
margin: 0;
display: none;
min-width: 300px; /* Changed this to accomodate content width */
max-height: auto;
margin-left: -1px; /* Add this to keep dropdown in line with edge of navbar */
overflow: hidden; /* Changed this from overflow-y:auto; to overflow:hidden; */
opacity: 0;
position: absolute;
white-space: nowrap;
z-index: 1;
will-change: width, height;
}
#hv:hover{
border-radius: 1px solid blue;
}
</style>
<body oncontextmenu="return false;">
<!-- Dropdown Structure -->
<!-- <ul id="dropdown1" class="dropdown-content">
<li>ALL</li>
<li>JEE MAIN</li>
<li>KERALA PSC</li>
<li>RAILWAY EXAMS</li>
</ul>
<nav style="height: 80px; padding: 10px;" class="white">
<div class="nav-wrapper ">
Logo
<ul class="right hide-on-med-and-down">
<li>Home</li>
<li><a class="dropdown-trigger black-text" href="#!" data-target="dropdown1">Competative Exams<i class="material-icons right">arrow_drop_down</i></a></li>
<li>Institution Exams</li>
<li>Notifications</li>
<li>Login / Register <i class="material-icons right">lock</i></li>
</ul>
</div>
</nav> -->
<nav style="height: 100px; padding: 15px;" class="white">
<div class="nav-wrapper white darken-3">
<img src="<?php echo base_url('assets/images/logo/tolle_logo2.png'); ?>" style="height:80px;" alt="logo">
<i class="material-icons">menu</i>
<ul class="right hide-on-med-and-down">
<li><a href="<?php echo base_url(''); ?>" class="black-text" >Home</a></li>
<li><a id="hv" class="dropdown-button black-text" href="#!" data-activates="dropdown" data-beloworigin="true">Competitive Exams<i class="material-icons right">arrow_drop_down</i></a></li>
<li><a id="hv" href="<?php echo base_url('ins_view'); ?>" class="black-text">Institution Exams</a></li>
<li><a id="hv" href="<?php echo base_url('notification/show_notification1'); ?>" class="black-text">Notifications</a></li>
<!-- Dropdown Trigger -->
<?php if($_SESSION['logged_in']==FALSE){ ?>
Login / Register <i class="material-icons right">lock</i>
<?php }else{ ?>
<a class="black-text" title="Dashboard" href="<?php echo base_url('admin/dashboard'); ?>">Welcome: <?php echo $_SESSION['name']; ?></a>
Logout <i class="material-icons right">lock_open
<?php } ?>
</ul>
</div>
</nav>
<ul id="dropdown" class="dropdown-content collection">
<li class="collection-item">
<a href="<?php echo base_url('exam/ALL'); ?>" >
<span class="title black-text">ALL EXAMS</span>
</a>
</li>
<?php foreach($categories as $cat): ?>
<li class="collection-item">
<a href="<?php echo base_url('exam/'.$cat['name']); ?>" >
<span class="title black-text"><?php echo $cat['name']; ?></span>
</a>
</li>
<?php endforeach; ?>
</ul>
<ul class="side-nav" id="mobile-demo">
<li><a href="<?php echo base_url(''); ?>" class="black-text" >Home</a></li>
</li>
<ul class="collapsible">
<li>
<div class="collapsible-header"><i class="material-icons">arrow_drop_down</i>Competitive Exams</div>
<?php foreach($categories as $cat): ?>
<div class="collapsible-body">
<a href="<?php echo base_url('exam/'.$cat['name']); ?>" >
<span class="title blue-text" ><?php echo $cat['name']; ?></span>
</a>
</div>
<?php endforeach; ?></li></ul>
<li><a id="hv" href="<?php echo base_url('ins_view'); ?>" class="black-text">Institution Exams</a></li>
<li><a id="hv" href="<?php echo base_url('notification/show_notification1'); ?>" class="black-text">Notifications</a></li>
<!-- Dropdown Trigger -->
<?php if($_SESSION['logged_in']==FALSE){ ?>
Login / Register <i class="material-icons right">lock</i>
<?php }else{ ?>
<a class="black-text" title="Dashboard" href="<?php echo base_url('admin/dashboard'); ?>">Welcome: <?php echo $_SESSION['name']; ?></a>
<li></li>Logout <i class="material-icons right">lock_open
<?php } ?>
</ul>
<!-- Dropdown Structure -->
Above is my Header File
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<script type="text/javascript" src="<?php echo base_url('assets/') ?>js/slippry.min.js"></script>
<script type="text/javascript" src="<?php echo base_url('assets/') ?>js/readmore.js"></script>
<script>
$(document).ready(function() {
// Configure/customize these variables.
var showChar = 100; // How many characters are shown by default
var ellipsestext = "...";
var moretext = "Show more >";
var lesstext = "Show less";
$('.more').each(function() {
var content = $(this).html();
if(content.length > showChar) {
var c = content.substr(0, showChar);
var h = content.substr(showChar, content.length - showChar);
var html = c + '<span class="moreellipses">' + ellipsestext+ ' </span><span class="morecontent"><span>' + h + '</span> ' + moretext + '</span>';
$(this).html(html);
}
});
$(".morelink").click(function(){
if($(this).hasClass("less")) {
$(this).removeClass("less");
$(this).html(moretext);
} else {
$(this).addClass("less");
$(this).html(lesstext);
}
$(this).parent().prev().toggle();
$(this).prev().toggle();
return false;
});
});
</script>
<script>
(function($) {
$(function() {
$('#article').readmore({
speed: 75,
lessLink: 'Read less'
});
$('.dropdown-button').dropdown({
inDuration: 300,
outDuration: 225,
hover: true, // Activate on hover
belowOrigin: true, // Displays dropdown below the button
alignment: 'right' // Displays dropdown with edge aligned to the left of button
}
);
}); // End Document Ready
})(jQuery); // End of jQuery name space
</script>
<?php
if( $this->session->flashdata('msg') ){
?>
<?php echo '<script>Materialize.toast("'.$this->session->flashdata('msg').'", 3000)</script>' ?>
<?php } ?>
<script type="text/javascript">
$(document).ready(function(){
$(".dropdown-trigger").dropdown();
$('.carousel.carousel-slider').carousel();
$('.collapsible').collapsible();
$('.button-collapse').sideNav();
$('.modal').modal();
$("#trigg").click(function(){
$("#viewMore").slideToggle("slow");
});
});
</script>
<script>
// count=0;
// $(document).ready(function() {
// var hidden, visibilityState, visibilityChange;
// if (typeof document.hidden !== "undefined") {
// hidden = "hidden", visibilityChange = "visibilitychange", visibilityState = "visibilityState";
// } else if (typeof document.msHidden !== "undefined") {
// hidden = "msHidden", visibilityChange = "msvisibilitychange", visibilityState = "msVisibilityState";
// }
// var document_hidden = document[hidden];
// document.addEventListener(visibilityChange, function() {
// if(document_hidden != document[hidden]) {
// if(document[hidden]) {
// // Document hidden
// alert('hidden');
// count++;
// } else {
// // Document shown
// alert('Revoked');
// if(count ==3){
// alert('Exceeded the Limit');
// }
// }
// document_hidden = document[hidden];
// }
// });
// });
</script>
<script>
function startExam(url) {
params = 'width='+screen.width;
params += ', height='+screen.height;
params += ', top=0, left=0'
params += ', fullscreen=yes';
params += ', directories=no';
params += ', location=no';
params += ', menubar=no';
params += ', resizable=no';
params += ', scrollbars=no';
params += ', status=no';
params += ', toolbar=no';
params += ', resizable=no';
newwin=window.open(url,'FullWindowAll', params);
if (window.focus) {newwin.focus()}
return false;
}
jQuery('#out-of-the-box-demo').slippry();
</script>
<script>
$(document).ready(function(){
$('.modal').modal();
});
</script>
</body>
</html>
THis is the footer
Some tags are not closed properly.
Somewhere closed </li> tag on the wrong position and somewhere you missed to closing </a> tags.

php database, jquery dynamic content load

I would like to achieve such an effect, except that when you click on the picture (link) jquery script sends a GET to the same file from the fact that with another ID. I mean the dynamic reload the page without refreshing the addition of a nice effect in the attached link.
my code :
<script>
$('a.menu').click(function(){
$('.content').html('');
})
</script>
<div class="content" id="page_effect" style="padding:0px; display:none;">
<div class="separator" style="margin: -17px auto;"></div>
<span class="choose-product"> Wybierz Produkt</span>
<p>
<?php
$kat=$_GET['kat'];
$co_ile_strona=9;
//----------------
$dopisz="";
if (is_numeric($kat)) {
$dopisz=" WHERE kat_id='".$kat."'";
$wyk=mysql_query("SELECT * FROM kategorie WHERE kat='".$kat."'");
while($ww=mysql_fetch_array($wyk)) {
$dopisz.=" OR kat_id='".$ww['id']."'";
}
}
$sile=false;
$wyk=mysql_query("SELECT * FROM produkty ".$dopisz."");
if ($ile=mysql_num_rows($wyk)) {
if (!$sile) {
$nazwa = mysql_fetch_assoc(mysql_query("SELECT * FROM kategorie WHERE id='".$_GET['kat']."'"));
if(strlen($nazwa['nazwa']) > 0)
$nazwa = $nazwa['nazwa'];
?>
<div style="text-align: center; width: 80%;margin: 0 auto;margin-top: 39px;">
<a href="produkt.html"><div class="product-box">
<img src="images/picasso0.png" alt="Product"/>
<span class="product-title"><?=$nazwa?></span>
</div>
</a>
<?
$sile=true;
}
if (!$_GET['strona']) $strona=1; else $strona=$_GET['strona'];
$start=($strona*$co_ile_strona)-$co_ile_strona;
mysql_data_seek($wyk,$start);
$licz=0;
while(($ww=mysql_fetch_object($wyk)) && $licz<$co_ile_strona) { $licz++;
?>
<a href="<?=strtolower(seo($ww->nazwa))?>-<?=$ww->id?>p.html"><div class="product-box">
<img src="produkty/front/<?=$ww->front?>" alt="<?=$ww->nazwa?>"/>
<div class="name2"><span><?=$ww->nazwa?> </span></div>
</div>
</a>
<?
}
} else echo "<span style='color: #ff0000; font-size: 12pt; font-weight: bold;'>Przepraszamy, ale nie znaleziono produktów pasujących do tego zapytania</span>";
?>
</div>
<div class="menu-bottom" style="text-align:center;">
<span style="position: relative;top: 25px;display: inline-flex;margin-bottom: 20px;">Wybierz serię:
<ul>
<?php
$zapas=$_GET['kat'];
$wyk=mysql_query("SELECT * FROM kategorie WHERE kat='0' and wid='1' ORDER BY poz ASC");
while($ww=mysql_fetch_object($wyk)) {
?> <!--<?/*=$ww->nazwa?>-<?=$ww->id*/?>k.html*/-->
<li> <? if($_GET['kat']==$ww->id) echo "<span style='color: #000;'>".$ww->nazwa.""; else echo $ww->nazwa?></li>
<? } ?>
</ul>
</span>
</div>
<!-- end .content --></div>
link : Click here
As mentioned in the comment, you should send an AJAX request to the page that is responsible for handling the database tasks. You can use get() or post() function which is a shorthand of AJAX function as stated in jQuery documentation.
$.ajax({
url: url,
data: data,
success: success,
dataType: dataType
});
I've prepared a simple jsFiddle demonstrating how the task can be achieved (please note the event.preventDefault() call):
$(document).ready(function(){
$("button").click(function(e){
var URL = '';
$.get(URL,function(data){
console.log("Status: " + status);
e.preventDefault();
});
});
});
Hope that helps.

Saving menu sorting position to backend

Introduction
I currently use the jQuery .sortable function and it works like a charm. However this is only client side and I would like to store the new sorting position to the backend (mySQL database).
I store the sorting order using numerical field (and retrieved using SQL ORDER BY).
Menu text Sorting ID
------------ ---------
Menu item #1 => 0
Menu item #2 => 1
Menu item #3 => 2
Menu item #4 => 3
Current HTML code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Sortable - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<style>
#sortable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
#sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: 18px; }
#sortable li span { position: absolute; margin-left: -1.3em; }
</style>
<script>
$(function() {
$( "#sortable" ).sortable();
$( "#sortable" ).disableSelection();
});
</script>
</head>
<body>
<ul id="sortable">
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Menu item #1</li>
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Menu item #2</li>
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Menu item #3</li>
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Menu item #4</li>
</ul>
</body>
</html>
Tinker.io link: http://tinker.io/b3f27
The question
Now, how would I store the new position into the database? Adding an ID to the sortable and posting it back to a php script which would lookup both sorting positions and switch them over is what I would do but I'm looking forward for your opinions.
This is basic idea is sending data using AJAX after update:
JS:
$("#sortable").sortable({
update : function () {
var items = $('#sortable').sortable('serialize');
$.get("sort.php?"+items);
}
});
HTML:
<ul id="sortable">
<li id="s_1" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Menu item #1</li>
<li id="s_2" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Menu item #2</li>
<li id="s_3" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Menu item #3</li>
<li id="s_4" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Menu item #4</li>
</ul>
Here you need to set id to each LI, please see working demo
PHP:
<?php
var_dump($_GET);
?>
You can find more detailed answers here

image fade on hover and show content

can I get some help here please
I got a code that is working for only one image but cannot for multiple images with different content
HTML
<ul id="base">
<li class="element" >
<img src="http://farm8.staticflickr.com/7040/6818412114_261c73da06_z.jpg" class="img1" />
<div style="display:none;" class="content">this is a text message 2</div>
</li>
<li class="element" >
<img src="http://farm8.staticflickr.com/7040/6818412114_261c73da06_z.jpg" class="img1" />
<div style="display:none;" class="content">this is a text message 2</div>
</li>
</ul>
CSS
.element {float:left;margin-right:15px;border:1px solid red;width:150px;height:150px;}
.element img {
position:absolute;
top:0;
left:0;
height:150px;
width:150px;
}
.content {height:150px;width:150px;background:gray;font-size:9px;}
jQuery
$(".element").hover(function() {
//fadeout first image using jQuery fadeOut
$(".img1").fadeOut(300);
//fadein second image using jQuery fadeIn
$(".content").fadeIn(300);
}, function () {
//fadeout second image using jQuery fadeOut
$(".img1").fadeIn(300);
//fadein first image using jQuery fadeIn
$(".content").fadeOut(300);
});
and a fiddle for testing http://jsfiddle.net/nQvay/1/, need some help
You must specify whose .img1 and .content you want to be faded
$(".element").hover(function() {
//fadeout first image using jQuery fadeOut
$(this).children(".img1").fadeOut(300);
//fadein second image using jQuery fadeIn
$(this).children(".content").fadeIn(300);
}, function () {
//fadeout second image using jQuery fadeOut
$(this).children(".img1").fadeIn(300);
//fadein first image using jQuery fadeIn
$(this).children(".content").fadeOut(300);
});
Try this
JSFIDDLE
$(document).ready(function(){
$(".element").hover(function() {
//fadeout first image using jQuery fadeOut
$(".element").children(".img1").fadeOut(300);
//fadein second image using jQuery fadeIn
$(".element").children(".content").fadeIn(300);
}, function () {
//fadeout second image using jQuery fadeOut
$(".element").children(".img1").fadeIn(300);
//fadein first image using jQuery fadeIn
$(".element").children(".content").fadeOut(300);
});
});
<ul id="base">
<li class="element" >
<img src="http://farm8.staticflickr.com/7040/6818412114_261c73da06_z.jpg" class="img1" />
<div style="display:none;" class="content">this is a text message 2</div>
</li>
<li class="element" >
<img src="http://farm8.staticflickr.com/7040/6818412114_261c73da06_z.jpg" class="img1" />
<div style="display:none;" class="content">this is a text message 2</div>
</li>
</ul>
<style>
ul{
padding:0px;
margin:0px;
list-style:none;
}
.element {float:left;margin-right:15px;border:1px solid red;width:150px;height:150px;position:relative;}
.element img {
position:absolute;
top:0;
left:0;
height:150px;
width:150px;
}
.content {height:150px;width:150px;background:gray;font-size:9px;}
</style>
<script>
$(".element").hover(function() {
//fadeout first image using jQuery fadeOut
$(this).children(".img1").fadeOut(300);
//fadein second image using jQuery fadeIn
$(this).children(".content").fadeIn(300);
}, function () {
//fadeout second image using jQuery fadeOut
$(this).children(".img1").fadeIn(300);
//fadein first image using jQuery fadeIn
$(this).children(".content").fadeOut(300);
});
</script>

Categories