Scrolling profiles of most recent members - javascript

I have a file recent.php that shows recent 15 members who has joined my website. Since 15 is a big number, I wish to have a scrolling effect on the page so that all recent 15 profiles will keep scrolling. Then I came across SimplyScroll but here is the issue that I am facing.
I downloaded the script and went through all the test files and I have understood how to do it if I have static images but dont know how to do it when there is a dynamic data that comes from database in form of html table (top 15 registered members and their profiles. Can someone help me where to make changes to get the scrolling effect? Here is the code of recent.php Thanks.
<?php
session_start()
include("connect/config.php");
if($_SESSION['gender123'])
{
if($_SESSION['gender123']=='Male')
{
$gender="where gender='Female'";
}
else
{
$gender="where gender='Male'";
}
}
$sql="select * from register $gender order by index_id DESC LIMIT 0,15";
$result=mysql_query($sql) or die(mysql_error());
$abcdef=$_SESSION['userid'];
$select="select * from payments where pmatri_id='$abcdef' or pemail='$abcdef'";
$exe=mysql_query($select) or die(mysql_error());
$fetch123=mysql_fetch_array($exe);
?>
<table width="210px" align="left" cellpadding="0" cellspacing="0" border="0" class="text2">
<tr valign="top">
<?php while($fetch=mysql_fetch_array($result)) { ?>
<td valign="top" align="left" height="55px" style="padding:1px; max-width:120px; min-width:120px;">
<?php if($_SESSION[ 'userid']) { if($fetch123[ 'profile']-$fetch123[ 'r_profile']>0) { ?>
<a href="memprofile.php?user_id=<?php echo $fetch['matri_id']; ?>">
<?php if($fetch[ 'photo1_approve']=="No" ) { ?>
<img src="images/No-Image-icon.png" height="100" width="90px" border="0" />
<?php } else if($fetch[ 'photo1']=='' ) { ?>
<img src="images/No-Image-icon.png" height="100" width="90px" border="0" />
<?php } else if($fetch[ 'photo_protect']=='Yes' ) { ?>
<img src="images/imagePassProtected.jpg" height="100" width="90px" border="0" />
<?php } else { ?>
<img src="photos/<?php echo $fetch['photo1']?>" height="100" width="90px" border="0" />
<?php } ?>
<br />
<h3><?php echo $fetch['firstname']." ".$fetch['lastname']; ?></h3>
</a>
</td>
<?php } ?>
</tr>
</table>

It's the same thing. Whether it is in a table or outside of a table. It's always the same procedure.
(function($) {
$(function() { //on DOM ready
$(".scroller").simplyScroll({
orientation: 'horizontal',
auto: true,
manualMode: 'loop',
frameRate: 20,
speed: 5
});
});
})(jQuery);
.simply-scroll-container {
/* Container DIV - automatically generated */
position: relative;
}
.simply-scroll-clip {
/* Clip DIV - automatically generated */
position: relative;
overflow: hidden;
}
.simply-scroll-list {
/* UL/OL/DIV - the element that simplyScroll is inited on */
overflow: hidden;
margin: 0;
padding: 0;
list-style: none;
}
.simply-scroll-list li {
padding: 0;
margin: 0;
list-style: none;
}
.simply-scroll-list li img {
border: none;
display: block;
}
.simply-scroll-btn {
position: absolute;
background-image: url(buttons.png);
width: 42px;
height: 44px;
z-index: 3;
cursor: pointer;
}
.simply-scroll-btn-left {
left: 6px;
bottom: 6px;
background-position: 0 -44px;
}
.simply-scroll-btn-left.disabled {
background-position: 0 0 !important;
}
.simply-scroll-btn-left:hover,
.simply-scroll-btn-left:focus {
background-position: 0 -88px;
}
.simply-scroll-btn-right {
right: 6px;
bottom: 6px;
background-position: -84px -44px;
}
.simply-scroll-btn-right.disabled {
background-position: -84px 0 !important;
}
.simply-scroll-btn-right:hover,
.simply-scroll-btn-right:focus {
background-position: -84px -88px;
}
.simply-scroll-btn-up {
right: 6px;
top: 6px;
background-position: -126px -44px;
}
.simply-scroll-btn-up.disabled {
background-position: -126px 0 !important;
}
.simply-scroll-btn-up:hover,
.simply-scroll-btn-up:focus {
background-position: -126px -88px;
}
.simply-scroll-btn-down {
right: 6px;
bottom: 6px;
background-position: -42px -44px;
}
.simply-scroll-btn-down.disabled {
background-position: -42px 0 !important;
}
.simply-scroll-btn-down:hover,
.simply-scroll-btn-down:focus {
background-position: -42px -88px;
}
.simply-scroll-btn-pause {
right: 6px;
bottom: 6px;
background-position: -168px -44px;
}
.simply-scroll-btn-pause:hover,
.simply-scroll-btn-pause:focus {
background-position: -168px -88px;
}
.simply-scroll-btn-pause.active {
background-position: -84px -44px;
}
.simply-scroll-btn-pause.active:hover,
.simply-scroll-btn-pause.active:focus {
background-position: -84px -88px;
}
/* Custom class modifications - override classees
.simply-scroll is default
*/
.simply-scroll {
/* Customisable base class for style override DIV */
width: 576px;
height: 200px;
margin-bottom: 1em;
}
.simply-scroll .simply-scroll-clip {
width: 576px;
height: 200px;
}
.simply-scroll .simply-scroll-list {} .simply-scroll .simply-scroll-list li {
float: left;
width: 290px;
height: 200px;
}
.simply-scroll .simply-scroll-list li img {} .simply-scroll .simply-scroll-btn {} .simply-scroll .simply-scroll-btn-left {} .simply-scroll .simply-scroll-btn-left.disabled {} .simply-scroll .simply-scroll-btn-left:hover {} .simply-scroll .simply-scroll-btn-right {} .simply-scroll .simply-scroll-btn-right.disabled {} .simply-scroll .simply-scroll-btn-right:hover {} .simply-scroll .simply-scroll-btn-up {} .simply-scroll .simply-scroll-btn-up.disabled {} .simply-scroll .simply-scroll-btn-up:hover {} .simply-scroll .simply-scroll-btn-down {} .simply-scroll .simply-scroll-btn-down.disabled {} .simply-scroll .simply-scroll-btn-down:hover {}
/* Vertical scroller example */
.vert {
/* wider than clip to position buttons to side */
width: 340px;
height: 400px;
margin-bottom: 1.5em;
}
.vert .simply-scroll-clip {
width: 290px;
height: 400px;
}
.vert .simply-scroll-list {} .vert .simply-scroll-list li {
width: 290px;
height: 200px;
}
.vert .simply-scroll-list li img {} .vert .simply-scroll-btn {} .vert .simply-scroll-btn-up {
/* modified btn pos */
right: 0;
top: 0;
}
.vert .simply-scroll-btn-up.disabled {} .vert .simply-scroll-btn-up:hover {} .vert .simply-scroll-btn-down {
/* modified btn pos */
right: 0;
top: 52px;
}
.vert .simply-scroll-btn-down.disabled {} .vert .simply-scroll-btn-down:hover {}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://budowastrony.pl/images/jquery.simplyscroll.js"></script>
<table>
<tr>
<td>
<ul class="scroller">
<li>
<img src="http://budowastrony.pl/images/img1.jpg" width="290" height="200">
</li>
<li>
<img src="http://budowastrony.pl/images/img2.jpg" width="290" height="200">
</li>
<li>
<img src="http://budowastrony.pl/images/img3.jpg" width="290" height="200">
</li>
<li>
<img src="http://budowastrony.pl/images/img4.jpg" width="290" height="200">
</li>
<li>
<img src="http://www.budowastrony.pl/images/img5.jpg" width="290" height="200">
</li>
</ul>
</td>
</tr>
<tr>
<td>
<ul class="scroller">
<li>
<img src="http://budowastrony.pl/images/img1.jpg" width="290" height="200">
</li>
<li>
<img src="http://budowastrony.pl/images/img2.jpg" width="290" height="200">
</li>
<li>
<img src="http://budowastrony.pl/images/img3.jpg" width="290" height="200">
</li>
<li>
<img src="http://budowastrony.pl/images/img4.jpg" width="290" height="200">
</li>
<li>
<img src="http://www.budowastrony.pl/images/img5.jpg" width="290" height="200">
</li>
</ul>
</td>
</tr>
</table>
<br />
<br />
<br />
<input type="text" value="" />
You might want to change from an id to a class when there are multiple rows you want to affect like I did in the example above. But the other things dont change.
I hope my example makes it clear how to work with it. If you really got multiple Slides it is important to change from id to class and do the same thing in your js code ( id="scroller" to class="scroller", $("#scroller") to $(".scroller") )

Related

how to add subtle transiton between images?

I created this question and was able to get my slider to work. Now I need to add a smooth transition between images. I tried transition/ animate in CSS but that has a weird effect - there is a blackness between images. I think the transition property needs to be added to JS.
Current situation - there is stark difference as images change suddenly
Expectation - I want images to ease in and out.
Any help in this direction is greatly appreciated!
P.S. -> copy-pasting code here for ease of use:
let line = document.getElementById("line");
line.addEventListener("input", function(event){
setNewImage(event.target.value);
});
function setNewImage(value){
// console.log(value);
let currentImage = document.getElementsByClassName("playing");
let removedImage = currentImage[0].classList.remove("playing");
let imageToAdd = "image"+value;
// console.log(imageToAdd);
let getElToAdd = document.getElementsByClassName(imageToAdd);
// console.log(getElToAdd);
let newEl = getElToAdd[0];
newEl.classList.add("playing");
}
.container {
display: flex;
justify-content: center;
flex-direction: column;
background-color: lavendar;
width: 400px;
height: 300px;
}
.image-container {
width: 380px;
height: 280px;
/* background-color: pink; */
}
.scrollbar {
/* padding: 0 5px 5px 0; */
}
.scrollbar input {
width: 380px;
}
ul li {
list-style: none;
}
.image {
width: 380px;
height: 260px;
display: none;
}
.playing {
display: block;
}
.image1 {
background: url('http://placekitten.com/380/260') no-repeat;
}
.image2 {
background: url('http://placekitten.com/378/260') no-repeat;
}
.image3 {
background: url('http://placekitten.com/380/259') no-repeat;
}
.image4 {
background: url('http://placekitten.com/379/260') no-repeat;
}
.image5 {
background: url('http://placekitten.com/383/260') no-repeat;
}
.image6 {
background: url('http://placekitten.com/380/261') no-repeat;
}
<div class="container">
<div class="image-container">
<ul>
<li><img class="playing image image1" /></li>
<li><img class="image image2" /></li>
<li ><img class="image image3" /></li>
<li><img class="image image4" /></img></li>
<li><img class="image image5" /></li>
<li><img class="image image6"/></li>
</ul>
</div>
<div class="scrollbar">
<input id="line" type="range" min=1 max =6 />
</div>
</div>
Use opacity instead of display to be able to add transition, and make your element position absolute to have them above each other:
let line = document.getElementById("line");
line.addEventListener("input", function(event) {
setNewImage(event.target.value);
});
function setNewImage(value) {
// console.log(value);
let currentImage = document.getElementsByClassName("playing");
let removedImage = currentImage[0].classList.remove("playing");
let imageToAdd = "image" + value;
// console.log(imageToAdd);
let getElToAdd = document.getElementsByClassName(imageToAdd);
// console.log(getElToAdd);
let newEl = getElToAdd[0];
newEl.classList.add("playing");
}
.container {
display: flex;
justify-content: center;
flex-direction: column;
background-color: lavendar;
width: 400px;
height: 300px;
}
.image-container {
width: 380px;
height: 280px;
}
.scrollbar input {
width: 380px;
}
ul {
position:relative; /*make them relative to ul not li*/
margin:0;
padding:0;
}
/* added this*/
ul li .image {
position:absolute;
top:0;
left:0;
}
/**/
ul li {
list-style: none;
}
.image {
width: 380px;
height: 260px;
opacity: 0;
transition:1s all;
}
.playing {
opacity:1;
}
.image1 {
background: url('http://placekitten.com/380/260') no-repeat;
}
.image2 {
background: url('http://placekitten.com/378/260') no-repeat;
}
.image3 {
background: url('http://placekitten.com/380/259') no-repeat;
}
.image4 {
background: url('http://placekitten.com/379/260') no-repeat;
}
.image5 {
background: url('http://placekitten.com/383/260') no-repeat;
}
.image6 {
background: url('http://placekitten.com/380/261') no-repeat;
}
<div class="container">
<div class="image-container">
<ul>
<li>
<div class="playing image image1"></div>
</li>
<li>
<div class="image image2"></div>
</li>
<li>
<div class="image image3"></div>
</li>
<li>
<div class="image image4"></div>
</li>
<li>
<div class="image image5"></div>
</li>
<li>
<div class="image image6"></div>
</li>
</ul>
</div>
<div class="scrollbar">
<input id="line" type="range" min=1 max=6>
</div>
</div>

how to transition between images in a slider

I have a simple image slider with input range. I want to pick input range value and be able to fade-in and fade out images.
The problem is - my setup has to remain this way. I need to have img tags within li and need to have images as css background url under classnames.
How do i identify the current playing and transition to the next depending on where the slider is?
Requirement: If user goes to range 2 on slider, image2 should be visible. if user goes to range 4, image4 should be visible and so on.
I have been able to read the input range and locate the image with that image class.
How do I remove the "active" state of previous one and insert this new image?
Please find code attached
let line = document.getElementById("line");
line.addEventListener("input", function(event){
setNewImage(event.target.value);
});
function setNewImage(value){
let currentImage = document.getElementsByClassName("playing");
let newImageClassName = "image"+value;
}
.container {
display: flex;
justify-content: center;
flex-direction: column;
background-color: lavendar;
width: 400px;
height: 300px;
}
.image-container {
width: 380px;
height: 280px;
/* background-color: pink; */
}
.scrollbar {
/* padding: 0 5px 5px 0; */
}
.scrollbar input {
width: 380px;
}
ul li {
list-style: none;
}
.image {
width: 380px;
height: 260px;
display: none;
}
.playing {
display: block;
}
.image1 {
background: url('http://placekitten.com/380/260') no-repeat;
}
.image2 {
background: url('http://placekitten.com/378/260') no-repeat;
}
.image3 {
background: url('http://placekitten.com/380/259') no-repeat;
}
.image4 {
background: url('http://placekitten.com/379/260') no-repeat;
}
.image5 {
background: url('http://placekitten.com/383/260') no-repeat;
}
.image6 {
background: url('http://placekitten.com/380/261') no-repeat;
}
<div class="container">
<div class="image-container">
<ul>
<li><img class="playing image image1" /></li>
<li><img class="image image2" /></li>
<li ><img class="image image3" /></li>
<li><img class="image image4" /></img></li>
<li><img class="image image5" /></li>
<li><img class="image image6"/></li>
</ul>
</div>
<div class="scrollbar">
<input id="line" type="range" min=1 max =6 />
</div>
</div>
I am getting the input range value. Help from here is greatly appreciated! Thanks!
I was able to solve it!
let line = document.getElementById("line");
line.addEventListener("input", function(event){
setNewImage(event.target.value);
});
function setNewImage(value){
// console.log(value);
let currentImage = document.getElementsByClassName("playing");
let removedImage = currentImage[0].classList.remove("playing");
let imageToAdd = "image"+value;
// console.log(imageToAdd);
let getElToAdd = document.getElementsByClassName(imageToAdd);
// console.log(getElToAdd);
let newEl = getElToAdd[0];
newEl.classList.add("playing");
}
.container {
display: flex;
justify-content: center;
flex-direction: column;
background-color: lavendar;
width: 400px;
height: 300px;
}
.image-container {
width: 380px;
height: 280px;
/* background-color: pink; */
}
.scrollbar {
/* padding: 0 5px 5px 0; */
}
.scrollbar input {
width: 380px;
}
ul li {
list-style: none;
}
.image {
width: 380px;
height: 260px;
display: none;
}
.playing {
display: block;
}
.image1 {
background: url('http://placekitten.com/380/260') no-repeat;
}
.image2 {
background: url('http://placekitten.com/378/260') no-repeat;
}
.image3 {
background: url('http://placekitten.com/380/259') no-repeat;
}
.image4 {
background: url('http://placekitten.com/379/260') no-repeat;
}
.image5 {
background: url('http://placekitten.com/383/260') no-repeat;
}
.image6 {
background: url('http://placekitten.com/380/261') no-repeat;
}
<div class="container">
<div class="image-container">
<ul>
<li><img class="playing image image1" /></li>
<li><img class="image image2" /></li>
<li ><img class="image image3" /></li>
<li><img class="image image4" /></img></li>
<li><img class="image image5" /></li>
<li><img class="image image6"/></li>
</ul>
</div>
<div class="scrollbar">
<input id="line" type="range" min=1 max =6 />
</div>
</div>

Javascript ordered image popup ... can't separate individual popups

ok, this is my first stab at javascript or coding in general so I hope this isn't too messy. My code is almost where I want it but I have run into one last problem -
I have a scrolling table of images and I'd like the viewer to be able to click each picture to enlarge it individually. I'm trying to do this through the showImage function as follows:
JS:
function showImage(largeimg01) {
document.getElementById("largeimg01").visibility = 'visible';
showLargeImagePanel();
unselectAll();
}
function showImage(largeimg02) {
document.getElementById("largeimg02").visibility = 'visible';
showLargeImagePanel();
unselectAll();
}
function showImage(largeimg03) {
document.getElementById("largeimg03").visibility = 'visible';
showLargeImagePanel();
unselectAll();
}
function showLargeImagePanel() {
document.getElementById('largeImgPanel').style.visibility = 'visible';
}
function unselectAll() {
if(document.selection) document.selection.empty();
if(window.getSelection) window.getSelection().removeAllRanges();
}
function hideMe(obj) {
obj.style.visibility = 'hidden';
}
HTML:
Leah Gotchel
<!-- javascript here -->
<link href="../wood-site-pagespopup.css" rel="stylesheet" type="text/css">
</head>
<body>
<a href="../index.html">
<p id="back"> LEAH GOTCHEL </p></a>
<!-- hidden popup images -->
<div id="largeImgPanel" onclick="hideMe(this);">
<img class="popup" id="largeimg01" src="../images/GUS_4735retweb.jpg" />
</div>
<div id="largeImgPanel" onclick="hideMe(this);">
<img class="popup" id="largeimg02" src="../images/GUS_5034retweb.jpg" />
</div>
<div id="largeImgPanel" onclick="hideMe(this);">
<img class="popup" id="largeimg03" src="../images/GUS_4735retweb.jpg" />
</div>
<div id="largeImgPanel" onclick="hideMe(this);">
<img class="popup" id="largeimg04" src="../images/GUS_4735retweb.jpg" />
</div>
<table>
<tr>
<td><img src="../images/GUS_4735retweb.jpg" id="img01" style="cursor:pointer"
onclick="showImage(largeimg01);"></td>
<td>
<img src="../images/GUS_5034retweb.jpg" id="img02" style="cursor:pointer"
onclick="showImage(largeimg02);">
</td>
<td><img src="../images/GUS_5060retweb.jpg" id="img03" style="cursor:pointer"
onclick="showImage(largeimg03);">
</td>
<td><img src='../images/GUS_5077retweb.jpg'" id="img04" style="cursor:pointer"
onclick="showImage(largeimg04);">
</td>
</tr>
</table>
<p id="caption">custom window bench: oak, poplar </p>
</body>
</html>
CSS:
html, body {
height:100%;
width:100%;
margin:0;}
html {
display:table;
}
body{
display:table-cell;
vertical-align:middle;
}
#back{
font-family: Corbert;
font-style: italic;
font-size: 2em;
color: ##006699;
position: relative;
padding: 30px;
margin-left: 20px;
}
img {
padding: 20px;
width: 500px;
}
a {
color: #006699;
margin: 0 auto;
text-decoration: none;
}
a:hover {
color: #8b98a7;
}
p {
position: fixed;
padding: 30px;
font-family: Verdana, Arial, sans-serif;
font-size: 12px;
clear: both;
margin-left: 20px;
}
table {
top: 50%
left: 50%
position: absolute;
border:none;
}
.popup {
position: relative;
height: 90%;
width: auto;
overflow: scroll;
}
.largeImgPanel {
text-align: center;
visibility: hidden;
position: fixed;
z-index: 100;
top: 0; left: 0; bottom: 0;
width:100%;
height:100%;
background-color: rgba(100,100,100, 0.5);
}
#largeImg {
height: auto;
max-width: 100%;
}
This code is close to what I found here: How to enlarge a clicked image with plain JavaScript on a mobile device
The popup is functioning - My problem is that, when I call on any one popup, all the popup images appear. The first popup (img01) is blocking the rest so they can't be seen. I think this is because they are all contained in divs with the same "largeImgPanel" id - but if they are not contained in the "largeImgPanel" div then they don't show up at all when I run the function. How can I change the script so that the function applies only to the specific popup image corresponding to the image that is being clicked?
This is my first post so I apologize if it's nonsensical! Any help is much appreciated. Please let me know if I can try to clarify.
All 4 images are named with the same id, largeImgPanel, so all 4 show when that function is called. Change the id to a class (put a dot instead of a # in your css) and give unique ids to your divs, keeping the class there
That should sort you out, but remember to call the relevant id!
EDIT:
Ok, so here's your WORKING (edited!) code
function showImage(imgname){
var mypic=document.getElementById(imgname);
mypic.style.visibility = 'visible';
mypic.style.zIndex = '20';
unselectAll();
}
function unselectAll() {
if(document.selection) document.selection.empty();
if(window.getSelection) window.getSelection().removeAllRanges();
}
function hideMe(obj) {
obj.style.visibility = 'hidden';
obj.style.zIndex = '-50';
}
html, body {
height:100%;
width:100%;
margin:0;}
html {
display:table;
}
body{
display:table-cell;
vertical-align:middle;
}
#back{
font-family: Corbert;
font-style: italic;
font-size: 2em;
color: ##006699;
position: relative;
padding: 30px;
margin-left: 20px;
}
td img {
padding: 20px;
width: 500px;
}
a {
color: #006699;
margin: 0 auto;
text-decoration: none;
}
a:hover {
color: #8b98a7;
}
p {
position: fixed;
padding: 30px;
font-family: Verdana, Arial, sans-serif;
font-size: 12px;
clear: both;
margin-left: 20px;
}
table {
top: 50%
left: 50%
position: absolute;
border:none;
}
.popup {
position: fixed;
text-align: center;
z-index: 0;
overflow-y: scroll;
top: 5px; left: 5px;
background-color: rgba(100,100,100, 0.5);
background-size:100% 100%;
}
#popup1, #popup2, #popup3, #popup4 {
visibility: hidden;
width:800px!important;
padding:25px;
height:auto;
margin:auto;
}
<!doctype html>
<html>
<body>
<a href="../index.html">
<p id="back"> LEAH GOTCHEL </p></a>
<!-- hidden popup images -->
<img class="popup" id="popup1" src="http://www.rachelgallen.com/images/daisies.jpg" alt="daisies" onclick="hideMe(this);" />
<img class="popup" id="popup2" src="http://www.rachelgallen.com/images/snowdrops.jpg" alt="snowdrops" onclick="hideMe(this);"/>
<img class="popup" id="popup3" src="http://www.rachelgallen.com/images/mountains.jpg" alt="mountains" onclick="hideMe(this);"/>
<img class="popup" id="popup4" src="http://www.rachelgallen.com/images/yellowflowers.jpg" alt="yellowflowers" onclick="hideMe(this);"/>
<table>
<tr>
<td><img src="http://www.rachelgallen.com/images/daisies.jpg" alt="daisies" id="img01" style="cursor:pointer"
onclick="showImage('popup1');"></td>
<td>
<img src="http://www.rachelgallen.com/images/snowdrops.jpg" alt="snowdrops" id="img02" style="cursor:pointer"
onclick="showImage('popup2');">
</td>
<td><img src="http://www.rachelgallen.com/images/mountains.jpg" alt="mountains" id="img03" style="cursor:pointer"
onclick="showImage('popup3');"></td>
<td><img src="http://www.rachelgallen.com/images/yellowflowers.jpg" alt="yellowflowers" id="img04" style="cursor:pointer"
onclick="showImage('popup4');">
</td>
</tr>
</table>
<p id="caption">custom window bench: oak, poplar </p>
</body>
</html>
You'll note that your javascript is neatly condensed into three functions, and that your ids are now unique. I got rid of the extra divs, why did you need them anyway, when you could just click on the image to hide it? Over-complicating things. Obviously the images have been replaced with dummy images from my website, but sure it works!

Top fixed Menubar, when linked to a certain div of the menu from another html

My problem is that i wanted to make a fixed menubar on top of the page when scrolled, that wasn't so hard, but the hard part for me is that, when i link it to a certain part from the menubar from external html the menubar shows up and it is fixed on the top of the page and it works perfectly when i scroll down, but when i scroll up, it stays there
<!DOCTYPE html>
<html>
<head>
<title>SMINT Demo</title>
<meta name = "keywords" content = "" />
<meta name = "description" content = "" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, minimum-scale=1 user-scalable=no">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300,400,700' rel='stylesheet' type='text/css'>
<link href="css/demo.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.smint.js"></script>
<script type="text/javascript">
$(document).ready( function() {
$('.subMenu').smint({
'scrollSpeed' : 1000
});
});
(function(){
$.fn.smint = function( options ) {
// adding a class to users div
$(this).addClass('smint');
var settings = $.extend({
'scrollSpeed ' : 500
}, options);
return $('.smint a').each( function() {
if ( settings.scrollSpeed ) {
var scrollSpeed = settings.scrollSpeed;
}
///////////////////////////////////
// get initial top offset for the menu
var stickyTop = $('.smint').offset().top;
// check position and make sticky if needed
var stickyMenu = function(){
// current distance top
var scrollTop = $(window).scrollTop();
// if we scroll more than the navigation, change its position to fixed and add class 'fxd', otherwise change it back to absolute and remove the class
if (scrollTop > stickyTop) {
$('.smint').css({ 'position': 'fixed', 'top':0 }).addClass('fxd');
} else {
$('.smint').css({ 'position': 'absolute', 'top':stickyTop }).removeClass('fxd');
}
};
// run function
stickyMenu();
// run function every time you scroll
$(window).scroll(function() {
stickyMenu();
});
///////////////////////////////////////
$(this).on('click', function(e){
// gets the height of the users div. This is used for off-setting the scroll so th emenu doesnt overlap any content in the div they jst scrolled to
var selectorHeight = $('.smint').height();
// stops empty hrefs making the page jump when clicked
e.preventDefault();
// get id pf the button you just clicked
var id = $(this).attr('id');
// gets the distance from top of the div class that matches your button id minus the height of the nav menu. This means the nav wont initially overlap the content.
var goTo = $('div.'+ id).offset().top -selectorHeight;
// Scroll the page to the desired position!
$("html, body").animate({ scrollTop: goTo }, scrollSpeed);
});
});
};
})();
function showImage(imgName) {
document.getElementById('largeImg').src = imgName;
showLargeImagePanel();
unselectAll();
}
function showLargeImagePanel() {
document.getElementById('largeImgPanel').style.visibility = 'visible';
}
function unselectAll() {
if(document.selection) document.selection.empty();
if(window.getSelection) window.getSelection().removeAllRanges();
}
function hideMe(obj) {
obj.style.visibility = 'hidden';
}
</script>
<style>
* {margin: 0; padding: 0; outline: 0;}
body {
color: #f8e0b3;
font-size: 12px;
background:#f8e0b3;
}
h1, h2 {
font-family: 'Open Sans', sans-serif;
font-weight: 300;
margin:0 0 15px 0;
}
h1 {
font-size: 36px;
letter-spacing: -2px;
line-height: 100%;
}
h1.title {
font-size: 46px;
font-weight: 700;
color: #f8e0b3;
}
h2 {
font-size: 24px;
}
p {
margin: 0 0 15px 0;
}
.menuBtn {
background: center center no-repeat transparent;
background: #f8e0b3;
display: block;
width: 40px;
height: 40px;
position: absolute;
top: 0;
left: 10px;
}
.clear {
clear: both;
}
.wrap {
/*background:url(../images/bg.png) top left repeat-x;*/
width: 100%;
max-width: 1140px;
min-width: 960px;
z-index: 10;
position: relative;
margin: 0 auto;
padding: 0;
}
.section {
width: 100%;
max-width: 1140px;
min-width: 960px;
z-index: 10;
position: relative;
margin: 0 auto;
padding: 0 0 20px 0;
}
.inner {
width: 960px;
margin: 0 auto;
position: relative;
min-height: 50px;
padding:30px 0;
font-size: 18px;
font-family: 'Open Sans', sans-serif;
font-weight: 300;
padding:30px 0;
}
/* This is the selector i used for my menu, it needs to be set as position:absolute; */
.subMenu {
position: absolute;
top: 400px;
height: 50px;
z-index: 1000;
width: 100%;
max-width: 1140px;
min-width: 960px;
background: #ff0000; /*за главна категория */
}
.subMenu .inner {
padding:0;
font-weight: 400;
}
.subNavBtn {
display: block;
height: 35px;
width: 8%;
float: left;
margin: 0px 0px 0 0;
text-decoration: none;
font-size: 14px;
padding: 15px 2% 0 2%;
text-align: center;
color: #fff;
}
.end {
margin: 0;
}
/* SECTIONS */
.sTop {
min-height: 630px;
background:#f8e0b3;
color:#3d3d3d;
}
.s1 {
min-height: 500px;
background: #f8e0b3;
}
.s2 {
min-height: 500px;
background: #f8e0b3;
}
.s3 {
min-height: 500px;
background: #f8e0b3;
}
.s4 {
min-height: 500px;
background: #f8e0b3;
}
.s5 {
min-height: 500px;
background: #f8e0b3;
}
.s6 {
min-height: 500px;
background: #f8e0b3;
}
.s7 {
min-height: 500px;
background: #f8e0b3;
}
h1.border {
border-style: solid;
border-width: 10px;
border-color: #ff0000;
}
h1 {
text-align: center;
}
p.border {
border-style: solid;
border-width: 10px;
border-color: #ff0000;
}
p {
text-align: center;
}
#largeImgPanel {
text-align: center;
visibility: hidden;
position: fixed;
z-index: 100;
top: 0; left: 0; width: 100%; height: 100%;
background-color: rgba(100,100,100, 0.5);
}
#displayImage{
border-style: solid;
border-color: red;
}
</style>
</head>
<body>
<div class="wrap">
<div class="subMenu" >
<div class="inner">
Блузи
Ризи
Сака
Аксесоари
Якета
Панталони/Дънки
Обувки
Спортни стоки
</div>
</div>
<div class="section sTop">
<div class="inner"><img src="heading.jpg" alt="заглавие">
<h1 class="border">Област Пловдив</h1>
<p class="border">Мъжки блузи</p>
</div>
<br class="clear">
</div>
<img id="displayImage" style="cursor:pointer" onclick="showImage(this.src)" src="hm/mujko/bluzi s kus dulag rukav/2.jpg" width="200" height="200" name="show">
<img id="displayImage" style="cursor:pointer" onclick="showImage(this.src)" src="hm/mujko/bluzi s kus dulag rukav/3.jpg" width="200" height="200" name="show">
<img id="displayImage" style="cursor:pointer" onclick="showImage(this.src)" src="hm/mujko/bluzi s kus dulag rukav/4.jpg" width="200" height="200" name="show">
<img id="displayImage" style="cursor:pointer" onclick="showImage(this.src)" src="hm/mujko/bluzi s kus dulag rukav/5.jpg" width="200" height="200" name="show">
<img id="displayImage" style="cursor:pointer" onclick="showImage(this.src)" src="hm/mujko/bluzi s kus dulag rukav/6.jpg" width="200" height="200" name="show">
<div class="section s1">
<h1 class="border"><font color="black"><a name="mujkirizi">Ризи</a><font></h1>
<img id="displayImage" style="cursor:pointer" onclick="showImage(this.src)" src="hm/mujko/rizi/hm (1).jpg" width="200" height="200" name="show">
</div>
<div class="section s2">
<h1 class="border"><font color="black"><a name="mujkisaka">Сака</a><font></h1>
<img id="displayImage" style="cursor:pointer" onclick="showImage(this.src)" src="hm/mujko/rizi/hm (1).jpg" width="200" height="200" name="show">
</div>
<div class="section s3">
<h1 class="border"><font color="black"><a name="mujkiaksesoari"> Аксесоари</a><font></h1>
<img id="displayImage" style="cursor:pointer" onclick="showImage(this.src)" src="hm/mujko/rizi/hm (1).jpg" width="200" height="200" name="show">
</div>
<div class="section s4">
<h1 class="border"><font color="black"><a name="mujkiiaketa"> Якета</a><font></h1>
<img id="displayImage" style="cursor:pointer" onclick="showImage(this.src)" src="hm/mujko/rizi/hm (1).jpg" width="200" height="200" name="show">
</div>
<div class="section s5">
<h1 class="border"><font color="black"><a name="mujkipantaloni"> Панталони/Дънки</a><font></h1>
<img id="displayImage" style="cursor:pointer" onclick="showImage(this.src)" src="hm/mujko/rizi/hm (1).jpg" width="200" height="200" name="show">
</div>
<div class="section s6">
<h1 class="border"><font color="black"><a name="mujkiobuvki"> Обувки</a><font></h1>
<img id="displayImage" style="cursor:pointer" onclick="showImage(this.src)" src="hm/mujko/rizi/hm (1).jpg" width="200" height="200" name="show">
</div>
<div class="section s7">
<h1 class="border"><font color="black"><a name="mujkisportnistoki"> Спортни стоки</a><font></h1>
<img id="displayImage" style="cursor:pointer" onclick="showImage(this.src)" src="hm/mujko/rizi/hm (1).jpg" width="200" height="200" name="show">
</div>
<div id="largeImgPanel" onclick="hideMe(this);">
<img id="largeImg" style="height: 100%; margin: 0; padding: 0;" />
</div>
</body>
</html>
It works for me, it's fixed when i scroll down, and when i come back on the top of the page it goes where it was at the beginning, i don't get your problem, can you be more specific?
Well, to be more specific, i have the menubar that is fixed when i scroll down or up and it work perfectly when i open this specific html. This menubar contain 7 submenus and my idea is that when i use an external html with link to for example submenu 3 using (it opens this specific html and scroll down to submenu 3)but the menubar doesnt move when i scroll up , it only works(stay fixed at the top)when i scroll down

Link back out from child HTML loaded in div to parent HTML

I have an id'd part of a child HTML file loaded into the parent HTML's div. I have a button at the top to empty out the child content and return the div to the parent content that was there previously. This is for an image gallery, with a main navigation (parent) and then the detailed view with smaller navigation (child). Here is the parent HTML, index.html (with CSS and JS embedded):
<html>
<head>
<title>Java Factory</title>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<style type="text/css">
#container {
width: 1020px;
height: 634px;
}
ul#flavors {
list-style: none;
width: 1020px;
height: 634px;
position: relative;
background: url(images/coffee/thumbs_large.jpg) no-repeat 0 0;
}
ul#flavors li {
position: absolute;
}
.wakey {
width: 309px;
height: 309px;
top: 0px;
left: 30px;
}
.smooth {
width: 309px;
height: 309px;
top: 0px;
left: 355px;
}
ul#flavors li a {
display: block;
outline: none;
height: 100%;
}
ul#flavors li a {
text-indent: -9000px;
}
ul#flavors li a:hover {
background: url(images/coffee/thumbs_large.jpg) no-repeat 0 0;
}
ul#flavors li.wakey a:hover {
background-position: -30px -640px;
}
ul#flavors li.smooth a:hover {
background-position: -355px -640px;
}
#top {
height: 36px;
margin-top: 10px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div id="web">
<div id="top">
</div>
<nav id="container">
<ul id="flavors" class="coffeenav">
<li class="wakey">Wakey Wakey</li>
<li class="smooth">Smooth Caffeinator</li>
</ul>
</nav>
</div>
<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
$('#web').on('click', '.coffeenav li a', function () {
$('#web').load('coffee.html #' + $(this).attr('href'));
return false;
});
});
</script>
</body>
</html>
And here is the child HTML:
<html>
<head>
<title>div container switch test</title>
<style type="text/css">
#coffee_return {
height: 36px;
margin-top: 10px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div id="wakey">
<style type="text/css">
.shell {
width:100%;
height:100%;
}
#container1 {
width: 1020px;
height: 624px;
background: url(images/coffee/wakey.jpg) no-repeat 0 0;
}
ul#flavors1 {
list-style: none;
width: 1020px;
height: 624px;
position: relative;
}
ul#flavors1 li {
position: absolute;
}
.wakey {
width: 159px;
height: 169px;
top: 455px;
left: 30px;
}
.smooth {
width: 159px;
height: 169px;
top: 455px;
left: 188px;
}
ul#flavors1 li a {
display: block;
outline: none;
height: 100%;
}
ul#flavors1 li a {
text-indent: -9000px;
}
ul#flavors1 li a:hover {
background: url(images/coffee/thumbsml_rollover.jpg) no-repeat 0 0;
}
ul#flavors1 li.wakey a:hover {
background-position: 1px 11px;
}
ul#flavors1 li.smooth a:hover {
background-position: -157px 11px;
}
#coffee_return {
margin-top: 10px;
margin-bottom: 10px;
}
</style>
<div class="shell">
<div id="coffee_return">
<img src="images/coffee/return_btn.jpg" border="0">
</div>
<nav id="container1">
<ul id="flavors1" class="coffeenav">
<li class="smooth">Smooth Caffeinator</li>
<li class="vanilla">Vanilla Dream</li>
</ul>
</nav>
</div>
<div class="clr"></div>
</div>
<div class="clr"></div>
<div id="smooth">
<style type="text/css">
.shell {
width:100%;
height:100%;
}
#container2 {
width: 1020px;
height: 624px;
background: url(images/coffee/smooth.jpg) no-repeat 0 0;
}
ul#flavors2 {
list-style: none;
width: 1020px;
height: 624px;
position: relative;
}
ul#flavors2 li {
position: absolute;
}
.wakey {
width: 159px;
height: 169px;
top: 455px;
left: 30px;
}
.smooth {
width: 159px;
height: 169px;
top: 455px;
left: 188px;
}
ul#flavors2 li a {
display: block;
outline: none;
height: 100%;
}
ul#flavors2 li a {
text-indent: -9000px;
}
ul#flavors2 li a:hover {
background: url(images/coffee/thumbsml_rollover.jpg) no-repeat 0 0;
}
ul#flavors2 li.wakey a:hover {
background-position: 1px 11px;
}
ul#flavors2 li.smooth a:hover {
background-position: -157px 11px;
}
</style>
<div class="shell">
<div id="coffee_return">
<img src="images/coffee/return_btn.jpg" border="0">
</div>
<nav id="container2">
<ul id="flavors2" class="coffeenav">
<li class="wakey">Wakey Wakey</li>
<li class="vanilla">Vanilla Dream</li>
</ul>
</nav>
</div>
<div class="clr"></div>
</div>
<div class="clr"></div>
</body>
</html>
The button inside each referenced div id in the child HTML is this:
<div id="coffee_return">
<img src="images/coffee/return_btn.jpg" border="0">
</div>
And the demo for this is: http://mmdsgn.com/divsample/5/ -- You'll see the return button appears at the top when you click either of the first two boxes (only ones that work right now) and I need that graphic button to call up the original div id content in the parent HTML.
Change the path on "href" to "../" instead of "x"
<img src="images/coffee/return_btn.jpg" border="0">
or remove it. Using # is not really recommended since your script looks for the content of href. So leaving it empty would cause the page to refresh? i'm not quite sure but it works.
<img src="images/coffee/return_btn.jpg" border="0">
Edit:
Now that i think about it. The first one would not work on your page since you are in the same folder. ;-)
You'll want to change your original script a bit:
<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
$('#web').on('click', '.coffeenav li a', function () {
$('#web').load('coffee.html #' + $(this).attr('href'),
function() {
$('#coffee_return').on('click', function () {
$('#web').load('./ #web');
return false;
});
});
return false;
});
});
</script>
This basically says: After loading a section of coffee.html, look for a coffee_return button and add onclick behavior to re-load the original page into your #web section.
Also, change that href on your coffee_return button to # or JavaScript:void(0); since it's trying to load a document called "x" currently:
<div id="coffee_return">
<img src="images/coffee/return_btn.jpg" border="0">
</div>
You cannot use same id on multiple elements, as you said
"
The button inside each referenced div id in the child HTML is this:
<div id="coffee_return">
<img src="images/coffee/return_btn.jpg" border="0">
</div>
". This would give erroneous results. Rather, assign them a class and bind event with their class.

Categories

Resources