I'm trying to create a simple breaking news bar with continuously moving text. A single string of text moving and looping forever, and only stopping on hover. Do you know of any script like that? I've searched a lot but couldn't find one.
Cheers
So far I have this:
<script type="text/javascript">
$(function() {
var ele = $('#scroll');
var speed = 25, scroll = 5, scrolling;
$('#scroll-up').mouseenter(function() {
// Scroll the element up
scrolling = window.setInterval(function() {
ele.scrollLeft( ele.scrollLeft() - scroll );
autoPlay: true;
}, speed);
});
$('#scroll-down').mouseenter(function() {
// Scroll the element down
scrolling = window.setInterval(function() {
ele.scrollLeft( ele.scrollLeft() + scroll );
autoPlay: true;
}, speed);
});
$('#scroll-up, #scroll-down').bind({
click: function(e) {
// Prevent the default click action
e.preventDefault();
},
mouseleave: function() {
if (scrolling) {
window.clearInterval(scrolling);
scrolling = false;
}
}
});
});
</script>
Now I want to make it automatic, and make it loop infinitely. Any help?
Here's something I hacked together based on your sample: http://jsfiddle.net/mcknz/jEGex/
It scrolls from top to bottom and then back to top, but uses vertical space to give the appearance of a loop. Could be made more elegant and dynamic I'm sure.
HTML:
<div id="scroll">
<br /><br /><br /><br /><br />
One<br /><br /><br />
Two<br /><br /><br />
Three<br /><br /><br />
Four<br /><br /><br />
Five<br /><br /><br />
Six<br /><br /><br />
Seven<br /><br /><br />
<br /><br /><br /><br />
</div>
<br>
scroll top: <span id="scrollTop"/>
JavaScript:
$(function() {
var ele = $('#scroll');
var speed = 35,
scroll = 1,
top = 0,
maxTop = 500,
scrolling;
ele.mouseleave(function() {
scrolling = window.setInterval(function() {
top = top === maxTop ? 0 : ele.scrollTop() + scroll;
ele.scrollTop(top);
$('#scrollTop').text(top);
}, speed);
});
ele.mouseenter(function() {
if (scrolling) {
window.clearInterval(scrolling);
scrolling = false;
}
});
ele.mouseleave();
});
CSS
#scroll {
width: 200px;
height: 100px;
overflow: hidden;
padding: 4px;
border: solid 1px #000;
}
Related
Hello I was making a website in which I want user to see their input in preview sections.
so if someone type: <h1>HELLO WORLD!</h1> then below preview section should show HELLO WORLD! as heading 1 in ejs.
<div class="form-group">
<label><i class="fad fa-texts"></i> Long Description<span style="color: rgb(175, 22, 22)">*</span>
<p class="text-muted">(Html supported but markdown not supported)</p>
</label>
<textarea name="longDesc" onkeypress="dis()" id="longDesc" class="form-control" minlength="300" required="required" style="width: 100%; height: 300px;"></textarea>
<textarea name="liveDesc" id="liveDesc" class="form-control" minlength="300" required="required" style="width: 100%; height: 300px;" disabled></textarea>
</div>
<script>
function dis (){
var botdesc = document.getElementById("longdesc");
var visualizer = document.getElementById("livedesc");
botdesc.addEventListener("keyup",async (e) => {
const dirtyhtml = marked(botdesc.value.replaceAll(/>+/g, ">").replaceAll(/<+/g, "<"));
const noicehtml = sanitizeHtml(dirtyhtml, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['discord-message','discord-messages', 'img','iframe', 'style', 'h1', 'h2', 'link', 'mark', 'svg', 'span']),
allowVulnerableTags: true,
allowedAttributes: {
'*': ["*"]
}
});
visualizer.innerHTML = noicehtml;
});
}
example below:
https://imgur.com/a/mSD6sKc
Using vanilla JavaScript, you can get a value from input or textarea and then push it in any element as HTML child nodes
For example, you have this HTML:
<textarea id="text" onkeyup="onChange()"></textarea>
<div id="htmlView"></div>
In this example, we are going to get value from the textarea and then push HTML nodes in the htmlView div
For this, we can write a function:
function onChange() {
// get value
const text = document.getElementById("text").value;
// set plain text as HTML nodes
document.getElementById("htmlView").innerHTML = text;
}
And, as you can see, it works
function onChange() {
const text = document.getElementById("text").value;
document.getElementById("htmlView").innerHTML = text;
}
<textarea id="text" onkeyup="onChange()"></textarea>
<div id="htmlView"></div>
I have a element that has gridstack initialised against it.
I want to save and reload my page, and i want the grid to be usable when the page is loaded. So when i load the page i want to re-initialise the gridstack element.
the trouble is it just adds duplicate classes into the element and its children.
<div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se" style="z-index: 90; display: none;"></div>
<div class="ui-resizable-handle ui-resizable-sw" style="z-index: 90; display: none;"></div>
<div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se" style="z-index: 90; display: none;"></div>
<div class="ui-resizable-handle ui-resizable-sw" style="z-index: 90; display: none;"></div>
also i get multiple classes added to the root element:
class="grid-stack grid-stack-instance-4036 grid-stack-instance-4052"
so what is the best way to re-initialise the grid?
So here's my solution to this issue:
var stacks = $(".grid-stack");
stacks.each(function () {
var grid = $(this).data("gridstack");
if (typeof grid !== "undefined") {
grid.destroy(false);
}
//use regex to remove the multiple classnames
$(this).removeClass(function (index, className) {
return (className.match(/(^|\s)grid-stack-instance-\S+/g) || []).join(" ");
});
$(this).find(".ui-resizable-handle").remove();
});
I want to display two charts in PrimeFaces.
I am using Bootstrap 1.0.10, PrimeFaces 5.3 and Tomcat 7.
The strange thing is, that the chart is rendered, but the user isn't able to see it.
stats.xhtml
<ui:define name="content">
<div>
<p:panel id="panel" header="Statistik"
style="margin: 20px;">
<p:chart type="pie" model="#{statistikBean.chartModel1}"
style="width:400px; height:300px" />
<p:chart type="metergauge"
model="#{statistikBean.chartModel2}"
style="width:400px; height:250px" />
</p:panel>
</div>
</ui:define>
StatistikBean.java
....
private PieChartModel chartModel1;
private MeterGaugeChartModel chartModel2;
#PostConstruct
public void init() {
doModels();
}
private void doModels() {
this.chartModel1 = new PieChartModel();
// chartModel1
this.chartModel1.set("Fach 1", 10);
this.chartModel1.set("Fach 2", 20);
this.chartModel1.set("Fach 3", 30);
this.chartModel1.set("Fach 4", 40);
this.chartModel1.setTitle("Verteilung der Facher");
this.chartModel1.setLegendPosition("w");
// chartModel2
List<Number> intervall = new ArrayList<Number>(){{
add(50);
add(75);
add(85);
add(95);
}};
this.chartModel2 = new MeterGaugeChartModel(75, intervall);
this.chartModel2.setTitle("Fortschritt");
this.chartModel2.setSeriesColors("cc6666,E7E658,93b75f,66cc66");
this.chartModel2.setGaugeLabel("%");
}
.....
Rendered Output :
<div>
<div id="panel"
class="ui-panel ui-widget ui-widget-content ui-corner-all"
style="margin: 20px;"
data-widget="widget_panel">
<div id="panel_header" class="ui-panel-titlebar ui-widget-header ui-helper-clearfix ui-corner-all">
<span class="ui-panel-title">Statistik</span>
</div>
<div id="panel_content" class="ui-panel-content ui-widget-content">
<div id="j_idt17" style="width:400px; height:300px"></div>
<script id="j_idt17_s" type="text/javascript">
$(function () {
PrimeFaces.cw('Chart', 'widget_j_idt17', {
id: 'j_idt17',
type: 'pie',
data: [[["Fach 1", 10], ["Fach 2", 20], ["Fach 3", 30], ["Fach 4", 40]]],
title: "Verteilung der Facher",
legendPosition: "w",
datatip: true,
datatipFormat: "%s - %d"}, 'charts');
});
</script>
<div id="j_idt18" style="width:400px; height:250px"></div>
<script id="j_idt18_s" type="text/javascript">
$(function () {
PrimeFaces.cw('Chart', 'widget_j_idt18', {
id: 'j_idt18',
type: 'metergauge',
data: [[75]],
title: "Fortschritt",
seriesColors: ["#cc6666", "#E7E658", "#93b75f", "#66cc66"],
intervals: [50, 75, 85, 95],
gaugeLabel: "%",
gaugeLabelPosition: "inside",
showTickLabels: true,
labelHeightAdjust: -25}, 'charts');
});
</script>
</div>
</div>
<script id="panel_s" type="text/javascript">
PrimeFaces.cw("Panel", "widget_panel", {id: "panel"});
</script>
</div>
Tested it in Chrome and FireFox. The area where the chart(s) should be is just white.
Ok, I found the problem. I accidentally included jQuery two times.
One time in the JSF-template (with bootstrap), the second time with Primefaces.
I removed it from the JSF-template and it now works.
I have started learning html , css, javascript just 3 weeks ago. Here is my first and very simple program. It has a form , the form has 3 buttons and nothing else. One of the buttons is initially hidden. Clicking on one of the other two buttons would make the hidden button visible. After making it visible, clicking on the third button would hide it again. Thats it , small simple program but it doesnt work. When I click the "show" button , the hidden button does not appear. I have been trying to fix it for 4 hours but I got no clue yet why its not working . Somebody help please. By the way I dont know nothing about jquery, so only javascript help please.
`
<meta charset="UTF-8" />
<title>Useless Form</title>
<script type="text/javascript" language="JavaScript">
var hidden = true ;
function show()
{
if (hidden)
{
document.getElementById("third").style.visibility = 'visible';
hidden = false ;
}
else
{
alert(" The button is already visible !") ;
}
}
function hide()
{
if (!hidden)
{
document.getElementById("third").style.visibility = 'hidden';
hidden = true ;
}
else
{
alert(" The button is already hidden !") ;
}
}
</script>
<style type="text/css">
h1
{
font-family: calibri;
text-align: center;
}
button
{
color: blue ;
font-size: 1em ;
margin-left: 133px;
}
table
{
margin-top: 190px;
}
form
{
position: absolute;
top: 8%;
bottom: 7%;
left: 15% ;
right: 15% ;
color: #fb9 ;
background-color: #420 ;
border: 4px double #C96333 ;
}
body { background-color: #000 ; }
<form>
<h1> My utter useless form </h1> <br>
<table>
<tr>
<td> <button id="first" onclick="show()" >show</button> </td>
<td> <button id="second" onclick="hide()">hide</button> </td>
<td> <button id="third" hidden>effected</button> </td>
</tr>
</table>
</form>
`
add the attribute: type="button" to all the buttons, or else the default attribute of type="submit" is used (causing an undesired page refresh).
<button type="button">
Then...
Your javascript doesn't actually toggle the html hidden attribute. This should work instead
show the element:
document.getElementById("third").removeAttribute("hidden");
hide the element:
document.getElementById("third").setAttribute("hidden", 'true');
Keep in mind, there are a multitude of methods to show and hide elements that you can research, but I'm conforming to your current design choice.
I have been trying to come up with a special 2 column layout.
Basically these are the requirements
Fixed width and centered
Height 100%
Header and Footer always visible
2 column content ( Main - Right )
Main column scroll on overflow
Right column fixed
Here is the code I have so far. I just haven't been able to center
the entire layout.
Live at www.onlinesportcenter.com
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SPECIAL 2 COLUMN LAYOUT</title>
<style type="text/css">
body {
margin:0;
border:0;
padding:0;
height:100%;
max-height:100%;
background:#fff;
font-family:arial, verdana, sans-serif;
font-size:76%;
overflow: hidden;
}
* html body {
padding:120px 0 20px 0;
}
#header {
position:absolute;
top:0;
left:0;
width:1004px;
height:119px;
overflow:auto;
background:#73a2bd;
border-bottom:1px solid #35759a;
text-align:center;
}
* html #header {height:120px;}
#header p {
color:#fff;
margin:2px 0 0 0;
}
#header ul {
clear:both;
text-align:center;
border-top:1px solid #73a2bd;
}
#header ul {
margin:0;
padding:0;
list-style-type:none;
background:transparent;
height:3em;
}
#header ul li {
display:inline;
color:#73a2bd;
}
#container {
font-family: Arial, sans-serif;
font-size: 1.2em;
position:fixed;
top:120px;
left:0;
bottom:20px;
right:0;
background:#fff;
padding:0;
width:1004px;
}
* html #container {
height:100%;
width:1004px;
}
#container img {margin:5px;}
#main {
width:774px;
height:100%;
float:left;
overflow:auto;
}
#right {
width:228px;
height:100%;
float:right;
border-left:1px solid #73a2bd;
border-right:1px solid #73a2bd;
}
#footer {
position:absolute;
bottom:0;
left:0;
width:1004px;
height:19px;
overflow:auto;
text-align:center;
background:#73a2bd;
border-top:1px solid #35759a;
}
* html #footer {height:20px;}
#footer p {
color:#fff;
margin:2px 0 0 0;
}
</style>
</head>
<body>
<div id="header">
<p>HEADER</p>
</div>
<div id="container">
<div id="main">
<p>
MAIN
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
</p>
</div>
<div id="right">
<p>
RIGHT
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
</p>
</div>
</div>
<div id="footer">
<p>FOOTER</p>
</div>
</body>
</html>
Wrap all top-level elements (header, container and main) in another div, give it a set width and a the following margin: "margin:0 auto;"
EDIT: I take my words back. I misunderstood your initial problem. For header and footer you need to wrap them in a absolute positioned div anchored to the top or bottom. Make sure those elements have width to 100%. Then set margin to "0 auto" for inside elements. I'll post a JS Fiddle example in a sec.
EDIT 2: Here's what I got so far: http://jsfiddle.net/NfSKf/