Updating the DOM based on scroll position with Twitter Bootstrap? - dom

If you look at this page: http://twitter.github.com/bootstrap/components.html
Note the submenu and it's position. Now scroll down - notice how it changes? I assumed they implemented it with the scrollspy plugin but I can't seem to figure out how to do it, all I can do is update which list element has the active class.
Any help would be much appreciated :)

You can find this bit of code in the application.js file, it doesn't look as though it's included in the download. It's available here...funnily enough the header comment reads
// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
// IT'S ALL JUST JUNK FOR OUR DOCS!
// ++++++++++++++++++++++++++++++++++++++++++
This is the part that does the heavy lifting I believe...haven't tested it, just stepped through the code in Chrome
// fix sub nav on scroll
var $win = $(window)
, $nav = $('.subnav')
, navTop = $('.subnav').length && $('.subnav').offset().top - 40
, isFixed = 0
processScroll()
$win.on('scroll', processScroll)
function processScroll() {
var i, scrollTop = $win.scrollTop()
if (scrollTop >= navTop && !isFixed) {
isFixed = 1
$nav.addClass('subnav-fixed')
} else if (scrollTop <= navTop && isFixed) {
isFixed = 0
$nav.removeClass('subnav-fixed')
}
}

CCBlackburn's answer is close though its missing the required stylesheet. For posterity I've also included the javascript. Anyway I got it working using the following:
Javascript
// fix sub nav on scroll
var $win = $(window)
, $nav = $('.subnav')
, navTop = $('.subnav').length && $('.subnav').offset().top - 40
, isFixed = 0
processScroll()
// hack sad times - holdover until rewrite for 2.1
$nav.on('click', function () {
if (!isFixed) setTimeout(function () { $win.scrollTop($win.scrollTop() - 47) }, 10)
})
$win.on('scroll', processScroll)
function processScroll() {
var i, scrollTop = $win.scrollTop()
if (scrollTop >= navTop && !isFixed) {
isFixed = 1
$nav.addClass('subnav-fixed')
} else if (scrollTop <= navTop && isFixed) {
isFixed = 0
$nav.removeClass('subnav-fixed')
}
}
Stylesheet
/* Fixed subnav on scroll, but only for 980px and up (sorry IE!) */
#media (min-width: 980px) {
.subnav-fixed {
position: fixed;
top: 40px;
left: 0;
right: 0;
z-index: 1020; /* 10 less than .navbar-fixed to prevent any overlap */
border-color: #d5d5d5;
border-width: 0 0 1px; /* drop the border on the fixed edges */
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 0;
-webkit-box-shadow: inset 0 1px 0 #fff, 0 1px 5px rgba(0,0,0,.1);
-moz-box-shadow: inset 0 1px 0 #fff, 0 1px 5px rgba(0,0,0,.1);
box-shadow: inset 0 1px 0 #fff, 0 1px 5px rgba(0,0,0,.1);
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false); /* IE6-9 */
}
.subnav-fixed .nav {
width: 938px;
margin: 0 auto;
padding: 0 1px;
}
.subnav .nav > li:first-child > a,
.subnav .nav > li:first-child > a:hover {
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 0;
}
}
/* LARGE DESKTOP SCREENS */
#media (min-width: 1210px) {
/* Update subnav container */
.subnav-fixed .nav {
width: 1168px; /* 2px less to account for left/right borders being removed when in fixed mode */
}
}

Related

facebook customer chat messenger positioning

So i've installed the facebook customer chat messenger plugin on my website and it works fine, but i need to align it to the left of the website and if possible also change the size of the button (it's huge).
my code is:
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = 'https://connect.facebook.net/pt_PT/sdk/xfbml.customerchat.js';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fmessengerBtn">
<script>
window.fbAsyncInit = function() {
FB.init({
xfbml: true,
version : "v3.2"
});
};
</script>
<div id="fb-root"></div>
<div class="fb-customerchat"
attribution=setup_tool
page_id="372545293082246"
theme_color="#0b9bb8"
greeting_dialog_display="fade"
greeting_dialog_delay="60"
ref="home"
logged_in_greeting="Fale conosco"
logged_out_greeting="Fale conosco">
</div>
</div>
i've tried just using CSS to align the container div but then the chat window will stay on the right side of the website... Is there some sort of attribute or option to set the thing to go to the left side instead? Surely this is something lots of other people have needed to do
also, the greeting_dialog_delay option doesn't seem to be working
The following CSS seems to work for now (since the classes may change) :
/* ***************
* FB on left side
******************/
/* This is for the circle position */
.fb_dialog.fb_dialog_advanced {
left: 18pt;
}
/* The following are for the chat box, on display and on hide */
iframe.fb_customer_chat_bounce_in_v2 {
left: 9pt;
}
iframe.fb_customer_chat_bounce_out_v2 {
left: 9pt;
}
I tweaked the code a bit in case you want to keep the widget on the bottom right but just move it over to the left some (e.g., it is blocking another element)
.fb_dialog.fb_dialog_advanced {
right: 18pt;
margin-right: 50px;
}
iframe.fb_customer_chat_bounce_in_v2 {
right: 9pt;
margin-right: 50px;
}
iframe.fb_customer_chat_bounce_out_v2 {
right: 9pt;
margin-right: 50px;
}
To add to #Cubakos' answer to get the bounce in and bounce out animation:
#keyframes fb_bounce_in_v2 {
0% {
opacity: 0;
transform: scale(0, 0);
transform-origin: bottom left;
}
50% {
transform: scale(1.03, 1.03);
transform-origin: bottom left;
}
100% {
opacity: 1;
transform: scale(1, 1);
transform-origin: bottom left;
}
}
#keyframes fb_bounce_out_v2 {
0% {
opacity: 1;
transform: scale(1, 1);
transform-origin: bottom left;
}
100% {
opacity: 0;
transform: scale(0, 0);
transform-origin: bottom left;
}
}
Try Below Code
.fb_dialog {
position: -webkit-sticky !important;
position: fixed !important;
bottom: 95px !important;
right: 30px !important;
}
Combining #Cubakos & #Kuttoosan answers + made an adjust for positing the chat bubble as the posted methods here no longer work for me.
/* The following is for the chat bubble */
.fb_dialog_content>iframe {
left: 18pt;
}
/* The following are for the chat box, on display and on hide */
iframe.fb_customer_chat_bounce_in_v2 {
left: 9pt;
}
iframe.fb_customer_chat_bounce_out_v2 {
left: 9pt;
}
/* The following are for the bounce in/out animations */
#keyframes fb_bounce_in_v2 {
0% {
opacity: 0;
transform: scale(0, 0);
transform-origin: bottom left;
}
50% {
transform: scale(1.03, 1.03);
transform-origin: bottom left;
}
100% {
opacity: 1;
transform: scale(1, 1);
transform-origin: bottom left;
}
}
#keyframes fb_bounce_out_v2 {
0% {
opacity: 1;
transform: scale(1, 1);
transform-origin: bottom left;
}
100% {
opacity: 0;
transform: scale(0, 0);
transform-origin: bottom left;
}
}
After a while, I realize that we couldn't customize this plugin by CSS because
"it isn’t possible to style the elements contained within an iframe as
you would with normal HTML elements on your site due to HTML
limitations"
https://wordpress.org/support/topic/resize-messenger-icon/
You can customize your chat plugin from Facebook Business Page only 3 things:
Alignment
Color
Bottom Spacing (For mobile and desktop)
In the right page, there are preview pages for you to know how your customization will be like.
After customizing, don't forget to click on the button PUBLISH to save your changes.
It's a pain that you cannot resize the logo or styling it more easily, I hope that Facebook in the future can give us more power to do what we want with this.
Was Simple as below.
.fb_dialog.fb_dialog_advanced iframe {
right: auto !important;
left: 2rem;
bottom: 2rem !important;
}
Here's how I edited it properly. Get ready for a fun navigation run! (learn from our wasted 4h)
Switch or login as your facebook professional account
Go to your facebook page
Click "Manage"
On the left menu, under "Your Tools" click "Messaging Settings"
(Now it takes you to a new dashboard)
On the left menu click inbox again (even though you are already on it)
Click top gear icon.
Under "Inbox Modes", click "View all settings"
Select Chat plugin on the left
Scroll down and voila... now you can edit the chat positioning

Why position sticky doesn't work for the footer

I just found out about position sticky in CSS. I thought this is really cool and eliminates the need of writing a JS function for this simple behaviour.
So, I thought I give it a try. In the following example the header is sticking to the top, but I don't understand why the footer is not sticking to the bottom:
body {
height: 180vh;
padding: 0;
margin: 10px 0;
}
header,
footer {
position: -webkit-sticky;
position: sticky;
padding: 10px;
color: #ffffff;
text-align: center;
}
header {
top: 0;
background-color: brown;
}
footer {
bottom: 0;
background-color: #2d3142;
}
<header>I'm sticking to the top of the page</header>
<footer>I'm sticking to the Bottom of the page</footer>
Why is that?
I'm not sure about sticky but if all you are trying to do is put your footer at the bottom you can try this.
.alwaysBottom {
position: absolute;
bottom: 0;
}

Show viewport width when resizing window in Chrome developer tools?

I use Chrome with developer tools docked to the right hand side of the window. Chrome used to show the viewport dimensions at the top right of the window, when you resize the viewport by dragging the central divider. I've always found it useful for testing responsive sites and media queries.
Since a recent update, this has disappeared. Is there a way to switch it back on?
I'm using the latest version (Version 49.0.2623.87) on Mac.
As mentioned it's a bug. For the time being a cheap workaround I've been using is put this into your console:
window.addEventListener('resize', function(event){
console.log(window.innerWidth);
});
Now just watch the console when you resize. It does the trick for basic width checking.
Here's a version that imitates the old resizer:
var b = document.createElement('div');
var bS = b.style;
bS.position = 'fixed';
bS.top = 0;
bS.right = 0;
bS.background = '#fff';
bS.padding = '5px';
bS.zIndex = 100000;
bS.display = 'block';
bS.fontSize = '12px';
bS.fontFamily = 'sans-serif';
b.innerText = window.innerWidth + 'x' + window.innerHeight;
b.addEventListener("click", function(){bS.display = 'none';}, false);
document.body.appendChild(b);
window.addEventListener('resize', function(event){
bS.display = 'block';
b.innerText = window.innerWidth + 'x' + window.innerHeight;
});
I must have too much time on my hands.. This is a css version if you are using media query breakpoints. You can't click it away though, although it might be possible to show it for a # number of seconds whenever the media query fires (using animations)...
body::before {
position: fixed;
top: 0;
right: 0;
z-index: 100000;
box-sizing: border-box;
display: block;
padding: 5px;
font-size: 12px;
font-family: sans-serif;
background: #fefaa5;
border: 1px solid #fff628;
content: 'xs';
}
#media (min-width: 480px) { body::before {content: 'sm';}}
#media (min-width: 768px) { body::before {content: 'md';}}
#media (min-width: 992px) { body::before {content: 'lg';}}
#media (min-width: 1200px) { body::before {content: 'xl';}}

How to have an image span whole page in tumblr theme?

As the title says, I'm wondering how to get this image to span the whole browser window/page instead of having the gray margins.
Im using this theme:
https://raw.githubusercontent.com/olleota/themes/master/paperweight/main.html
And, its in action here:
http://fvcking5hit.tumblr.com/
where you see the gray borders and I just want it to span the whole page wile keeping the fade effect.
OK thank you for the additional comment, this should be all the code you need.
Find this code in your theme (it's showing at around line 226):
#masthead {
margin: 0 10%;
padding: 15% 0;
width: 80%;
}
Change it to:
#masthead {
margin: 0;
padding: 15% 0;
width:100%;
}
There are several references to #masthead in your css, so you will need to target the last reference for this to work (or tidy up the css by removing the old properties).
UPDATE
As you pointed out there is a media query changing the properties of the masthead.
Find this code:
#media (min-width: 1500px){
.theme-name-Paperweight #masthead {
margin: 0 20%;
width: 60%;
padding: 10% 0;
}
}
And change to:
#media (min-width: 1500px) {
.theme-name-Paperweight #masthead {
margin: 0;
width: 100%;
padding: 10% 0;
}
}

Display an icon in jQuery UI autocomplete results

I'm using the jQuery UI Autocomplete plugin (version 1.8), and I'd like to customize the way the suggestions show up. Specifically, I want to display not only some text, but an icon as well. However, when I send the <img> tag, it just gets rendered as plain text in the results list.
Is there some way to change this behavior? Alternatively, can you suggest a different way to include images in the returned results and have them show up in the suggestions?
Taken from here
$("#search_input").autocomplete({source: "/search",
minLength: 3,
select: function (event, ui) {
document.location = ui.item.url;
}
})
.data("autocomplete")._renderItem = function (ul, item) {
//As per recent documemtation above line should be
//.autocomplete( "instance" )._renderItem = function (ul, item) {
return $('<li class="ui-menu-item-with-icon"></li>')
.data("item.autocomplete", item)
.append('<a><span class="' + item.type + '-item-icon"></span>' + item.label + '</a>')
.appendTo(ul);
};
And the CSS:
.ui-menu .ui-menu-item-with-icon a {
padding-left: 20px;
}
span.group-item-icon,
span.file-item-icon {
display: inline-block;
height: 16px;
width: 16px;
margin-left: -16px;
}
span.group-item-icon {
background: url("/image/icons/group.png") no-repeat left 4px;
}
span.product-item-icon {
background: url("/image/icons/product.png") no-repeat left 7px;
}