Canvas width and height in HTML5 - html

Is it possible to fix the width and height of an HTML5 canvas element?
The usual way is the following :
<canvas id="canvas" width="300" height="300"></canvas>

The canvas DOM element has .height and .width properties that correspond to the height="…" and width="…" attributes. Set them to numeric values in JavaScript code to resize your canvas. For example:
var canvas = document.getElementsByTagName('canvas')[0];
canvas.width = 800;
canvas.height = 600;
Note that this clears the canvas, though you should follow with ctx.clearRect( 0, 0, ctx.canvas.width, ctx.canvas.height); to handle those browsers that don't fully clear the canvas. You'll need to redraw of any content you wanted displayed after the size change.
Note further that the height and width are the logical canvas dimensions used for drawing and are different from the style.height and style.width CSS attributes. If you don't set the CSS attributes, the intrinsic size of the canvas will be used as its display size; if you do set the CSS attributes, and they differ from the canvas dimensions, your content will be scaled in the browser. For example:
// Make a canvas that has a blurry pixelated zoom-in
// with each canvas pixel drawn showing as roughly 2x2 on screen
canvas.width = 400;
canvas.height = 300;
canvas.style.width = '800px';
canvas.style.height = '600px';
See this live example of a canvas that is zoomed in by 4x.
var c = document.getElementsByTagName('canvas')[0];
var ctx = c.getContext('2d');
ctx.lineWidth = 1;
ctx.strokeStyle = '#f00';
ctx.fillStyle = '#eff';
ctx.fillRect( 10.5, 10.5, 20, 20 );
ctx.strokeRect( 10.5, 10.5, 20, 20 );
ctx.fillRect( 40, 10.5, 20, 20 );
ctx.strokeRect( 40, 10.5, 20, 20 );
ctx.fillRect( 70, 10, 20, 20 );
ctx.strokeRect( 70, 10, 20, 20 );
ctx.strokeStyle = '#fff';
ctx.strokeRect( 10.5, 10.5, 20, 20 );
ctx.strokeRect( 40, 10.5, 20, 20 );
ctx.strokeRect( 70, 10, 20, 20 );
body { background:#eee; margin:1em; text-align:center }
canvas { background:#fff; border:1px solid #ccc; width:400px; height:160px }
<canvas width="100" height="40"></canvas>
<p>Showing that re-drawing the same antialiased lines does not obliterate old antialiased lines.</p>

A canvas has 2 sizes, the dimension of the pixels in the canvas (it's backingstore or drawingBuffer) and the display size. The number of pixels is set using the the canvas attributes. In HTML
<canvas width="400" height="300"></canvas>
Or in JavaScript
someCanvasElement.width = 400;
someCanvasElement.height = 300;
Separate from that are the canvas's CSS style width and height
In CSS
canvas { /* or some other selector */
width: 500px;
height: 400px;
}
Or in JavaScript
canvas.style.width = "500px";
canvas.style.height = "400px";
The arguably best way to make a canvas 1x1 pixels is to ALWAYS USE CSS to choose the size then write a tiny bit of JavaScript to make the number of pixels match that size.
function resizeCanvasToDisplaySize(canvas) {
// look up the size the canvas is being displayed
const width = canvas.clientWidth;
const height = canvas.clientHeight;
// If it's resolution does not match change it
if (canvas.width !== width || canvas.height !== height) {
canvas.width = width;
canvas.height = height;
return true;
}
return false;
}
Why is this the best way? Because it works in most cases without having to change any code.
Here's a full window canvas:
const ctx = document.querySelector("#c").getContext("2d");
function render(time) {
time *= 0.001;
resizeCanvasToDisplaySize(ctx.canvas);
ctx.fillStyle = "#DDE";
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
ctx.save();
const spacing = 64;
const size = 48;
const across = ctx.canvas.width / spacing + 1;
const down = ctx.canvas.height / spacing + 1;
const s = Math.sin(time);
const c = Math.cos(time);
for (let y = 0; y < down; ++y) {
for (let x = 0; x < across; ++x) {
ctx.setTransform(c, -s, s, c, x * spacing, y * spacing);
ctx.strokeRect(-size / 2, -size / 2, size, size);
}
}
ctx.restore();
requestAnimationFrame(render);
}
requestAnimationFrame(render);
function resizeCanvasToDisplaySize(canvas) {
// look up the size the canvas is being displayed
const width = canvas.clientWidth;
const height = canvas.clientHeight;
// If it's resolution does not match change it
if (canvas.width !== width || canvas.height !== height) {
canvas.width = width;
canvas.height = height;
return true;
}
return false;
}
body { margin: 0; }
canvas { display: block; width: 100vw; height: 100vh; }
<canvas id="c"></canvas>
And Here's a canvas as a float in a paragraph
const ctx = document.querySelector("#c").getContext("2d");
function render(time) {
time *= 0.001;
resizeCanvasToDisplaySize(ctx.canvas);
ctx.fillStyle = "#DDE";
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
ctx.save();
const spacing = 64;
const size = 48;
const across = ctx.canvas.width / spacing + 1;
const down = ctx.canvas.height / spacing + 1;
const s = Math.sin(time);
const c = Math.cos(time);
for (let y = 0; y <= down; ++y) {
for (let x = 0; x <= across; ++x) {
ctx.setTransform(c, -s, s, c, x * spacing, y * spacing);
ctx.strokeRect(-size / 2, -size / 2, size, size);
}
}
ctx.restore();
requestAnimationFrame(render);
}
requestAnimationFrame(render);
function resizeCanvasToDisplaySize(canvas) {
// look up the size the canvas is being displayed
const width = canvas.clientWidth;
const height = canvas.clientHeight;
// If it's resolution does not match change it
if (canvas.width !== width || canvas.height !== height) {
canvas.width = width;
canvas.height = height;
return true;
}
return false;
}
span {
width: 250px;
height: 100px;
float: left;
padding: 1em 1em 1em 0;
display: inline-block;
}
canvas {
width: 100%;
height: 100%;
}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent cursus venenatis metus. Mauris ac nibh at odio scelerisque scelerisque. Donec ut enim <span class="diagram"><canvas id="c"></canvas></span>
vel urna gravida imperdiet id ac odio. Aenean congue hendrerit eros id facilisis. In vitae leo ullamcorper, aliquet leo a, vehicula magna. Proin sollicitudin vestibulum aliquet. Sed et varius justo.
<br/><br/>
Quisque tempor metus in porttitor placerat. Nulla vehicula sem nec ipsum commodo, at tincidunt orci porttitor. Duis porttitor egestas dui eu viverra. Sed et ipsum eget odio pharetra semper. Integer tempor orci quam, eget aliquet velit consectetur sit amet. Maecenas maximus placerat arcu in varius. Morbi semper, quam a ullamcorper interdum, augue nisl sagittis urna, sed pharetra lectus ex nec elit. Nullam viverra lacinia tellus, bibendum maximus nisl dictum id. Phasellus mauris quam, rutrum ut congue non, hendrerit sollicitudin urna.
</p>
Here's a canvas in a sizable control panel
const ctx = document.querySelector("#c").getContext("2d");
function render(time) {
time *= 0.001;
resizeCanvasToDisplaySize(ctx.canvas);
ctx.fillStyle = "#DDE";
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
ctx.save();
const spacing = 64;
const size = 48;
const across = ctx.canvas.width / spacing + 1;
const down = ctx.canvas.height / spacing + 1;
const s = Math.sin(time);
const c = Math.cos(time);
for (let y = 0; y < down; ++y) {
for (let x = 0; x < across; ++x) {
ctx.setTransform(c, -s, s, c, x * spacing, y * spacing);
ctx.strokeRect(-size / 2, -size / 2, size, size);
}
}
ctx.restore();
requestAnimationFrame(render);
}
requestAnimationFrame(render);
function resizeCanvasToDisplaySize(canvas) {
// look up the size the canvas is being displayed
const width = canvas.clientWidth;
const height = canvas.clientHeight;
// If it's resolution does not match change it
if (canvas.width !== width || canvas.height !== height) {
canvas.width = width;
canvas.height = height;
return true;
}
return false;
}
// ----- the code above related to the canvas does not change ----
// ---- the code below is related to the slider ----
const $ = document.querySelector.bind(document);
const left = $(".left");
const slider = $(".slider");
let dragging;
let lastX;
let startWidth;
slider.addEventListener('mousedown', e => {
lastX = e.pageX;
dragging = true;
});
window.addEventListener('mouseup', e => {
dragging = false;
});
window.addEventListener('mousemove', e => {
if (dragging) {
const deltaX = e.pageX - lastX;
left.style.width = left.clientWidth + deltaX + "px";
lastX = e.pageX;
}
});
body {
margin: 0;
}
.frame {
display: flex;
align-items: space-between;
height: 100vh;
}
.left {
width: 70%;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
canvas {
width: 100%;
height: 100%;
}
pre {
padding: 1em;
}
.slider {
width: 10px;
background: #000;
}
.right {
flex 1 1 auto;
}
<div class="frame">
<div class="left">
<canvas id="c"></canvas>
</div>
<div class="slider">
</div>
<div class="right">
<pre>
* controls
* go
* here
<- drag this
</pre>
</div>
</div>
here's a canvas as a background
const ctx = document.querySelector("#c").getContext("2d");
function render(time) {
time *= 0.001;
resizeCanvasToDisplaySize(ctx.canvas);
ctx.fillStyle = "#DDE";
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
ctx.save();
const spacing = 64;
const size = 48;
const across = ctx.canvas.width / spacing + 1;
const down = ctx.canvas.height / spacing + 1;
const s = Math.sin(time);
const c = Math.cos(time);
for (let y = 0; y < down; ++y) {
for (let x = 0; x < across; ++x) {
ctx.setTransform(c, -s, s, c, x * spacing, y * spacing);
ctx.strokeRect(-size / 2, -size / 2, size, size);
}
}
ctx.restore();
requestAnimationFrame(render);
}
requestAnimationFrame(render);
function resizeCanvasToDisplaySize(canvas) {
// look up the size the canvas is being displayed
const width = canvas.clientWidth;
const height = canvas.clientHeight;
// If it's resolution does not match change it
if (canvas.width !== width || canvas.height !== height) {
canvas.width = width;
canvas.height = height;
return true;
}
return false;
}
body { margin: 0; }
canvas {
display: block;
width: 100vw;
height: 100vh;
position: fixed;
}
#content {
position: absolute;
margin: 0 1em;
font-size: xx-large;
font-family: sans-serif;
font-weight: bold;
text-shadow: 2px 2px 0 #FFF,
-2px -2px 0 #FFF,
-2px 2px 0 #FFF,
2px -2px 0 #FFF;
}
<canvas id="c"></canvas>
<div id="content">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent cursus venenatis metus. Mauris ac nibh at odio scelerisque scelerisque. Donec ut enim vel urna gravida imperdiet id ac odio. Aenean congue hendrerit eros id facilisis. In vitae leo ullamcorper, aliquet leo a, vehicula magna. Proin sollicitudin vestibulum aliquet. Sed et varius justo.
</p>
<p>
Quisque tempor metus in porttitor placerat. Nulla vehicula sem nec ipsum commodo, at tincidunt orci porttitor. Duis porttitor egestas dui eu viverra. Sed et ipsum eget odio pharetra semper. Integer tempor orci quam, eget aliquet velit consectetur sit amet. Maecenas maximus placerat arcu in varius. Morbi semper, quam a ullamcorper interdum, augue nisl sagittis urna, sed pharetra lectus ex nec elit. Nullam viverra lacinia tellus, bibendum maximus nisl dictum id. Phasellus mauris quam, rutrum ut congue non, hendrerit sollicitudin urna.
</p>
</div>
Because I didn't set the attributes the only thing that changed in each sample is the CSS (as far as the canvas is concerned)
Notes:
Don't put borders or padding on a canvas element. Computing the size to subtract from the number of dimensions of the element is troublesome

Thank you very much! Finally I solved the blurred pixels problem with this code:
<canvas id="graph" width=326 height=240 style='width:326px;height:240px'></canvas>
With the addition of the 'half-pixel' does the trick to unblur lines.

Related

How to disable text wrapping when viewport border is reached?

Consider code snippet below (you can click and drag outside the text) - the text is wrapping when viewport border is reached.
let isCaptureActive = false;
let offset = {
x: 0,
y: 0
}
const fooDOM = document.querySelector('#foo');
const bodyDOM = document.body;
window.addEventListener('mousemove', e => {
if(!isCaptureActive) return;
offset.x += e.movementX;
offset.y += e.movementY;
fooDOM.style.left = offset.x + 'px';
fooDOM.style.top = offset.y + 'px';
});
window.addEventListener('mousedown', e => {
if(e.target !== fooDOM) isCaptureActive = true;
});
window.addEventListener('mouseup', e => {
isCaptureActive = false;
});
#foo {
position: absolute;
background-color: wheat;
min-width: 250px;
max-width: 500px;
}
<div id="foo">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras porta nisl justo, id rutrum lorem cursus in. Nullam dictum lobortis lorem, vitae facilisis lectus. Donec ut eros lacinia, suscipit nisl ut, convallis diam.
</div>
How to make text ignore viewport border like it's not even there?
EDIT: I need to be able to set the element's min-width and max-width attributes.
let isCaptureActive = false;
let offset = {
x: 0,
y: 0
}
const fooDOM = document.querySelector('#foo');
const bodyDOM = document.body;
window.addEventListener('mousemove', e => {
if(!isCaptureActive) return;
offset.x += e.movementX;
offset.y += e.movementY;
fooDOM.style.left = offset.x + 'px';
fooDOM.style.top = offset.y + 'px';
});
window.addEventListener('mousedown', e => {
if(e.target !== fooDOM) isCaptureActive = true;
});
window.addEventListener('mouseup', e => {
isCaptureActive = false;
});
#foo {
position: absolute;
background-color: wheat;
min-width: 250px;
max-width: 500px;
}
#pg {
width: 100vw;
}
<div id="foo">
<p id='pg'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras porta nisl justo, id rutrum lorem cursus in. Nullam dictum lobortis lorem, vitae facilisis lectus. Donec ut eros lacinia, suscipit nisl ut, convallis diam.
</p>
</div>
I simply wrapped the text inside a <p> element and set its width to 100vw.

componentDidMount in React and the real DOM

I am trying to get the height on an element.
I want the parent div to adjust its height to the first paragraph of its children paragraph elements. Then a "Read More"/"Read Less" button expands the parent div to reveal all paragraphs or shrinks to only one paragraph.
I have experimented with useEffect, useLayoutEffect and componentDidMount in a class component and they all seem to need a setTimeout delay for the parent div to attain the perfect height.
Sorry if my code is fuzzy. I am new to React. :)
TIA
import styled from 'styled-components'
import React, { useRef, useLayoutEffect, useState } from 'react'
const CatIntroStyled = styled.div`
width: 1000px;
margin: 0 auto;
button{
display: block;
margin: 0 auto;
background: none;
}
button:focus{
outline: none;
}
`
const IntroText = styled.div`
height: ${({introStyle})=>{
if(introStyle.initIntroHeight === "auto") return "auto"
return introStyle.introExpanded ? introStyle.initIntroHeight+"px": introStyle.initFirstPara+"px";
}};
overflow: hidden;
transition: all 1s;
margin-bottom: 2rem
`
const formatIntro = (text, paraRef)=>{
let formatedText = text.replace(/<[^>]*>?/gm, "").replace(/\n\r/g, "")
let returnText = formatedText.split("\r\n").map((paragraph, key) => {
if(key===0) return <p ref={paraRef} key={key}>{paragraph}</p>;
return <p key={key}>{paragraph}</p>
})
return returnText
}
const CatIntro = ({title, text})=>{
const firstIntroPara = useRef();
const introRef = useRef();
const [intro, setIntro] = useState({
initFirstPara: 0,
initIntroHeight: "auto",
introExpanded: false
})
useLayoutEffect(()=>{
setTimeout(()=>{
setIntro({
...intro,
initIntroHeight: introRef.current.offsetHeight,
initFirstPara: firstIntroPara.current.offsetHeight,
})
}, 1000)
}, [])
return(
<CatIntroStyled>
<h1 className="globalTitleStyle">{title}</h1>
<IntroText ref={introRef} introStyle={intro}>
{formatIntro(text, firstIntroPara)}
</IntroText>
<button onClick={(e)=>{
setIntro({
...intro,
introExpanded: !intro.introExpanded
})
}}>{ intro.introExpanded ? "READ LESS": "READ MORE" }</button>
</CatIntroStyled>
)
}
export default CatIntro
Is there a more robust way of knowing when elements are truly painted on the screen?
TIA
Try using useLayoutEffect.
This runs synchronously immediately after React has performed all DOM mutations. This can be useful if you need to make DOM measurements (like getting the scroll position or other styles for an element).
Example
function App() {
const divRef = React.useRef(null);
React.useLayoutEffect(() => {
console.log(divRef.current.clientHeight)
}, [])
return (
<div ref={divRef} style={{ height: 100, width: 100, backgroundColor: 'red' }}/>
);
}
For this :- You need to change your class component to functional ones.
Maybe i don't fully understand why you need the height.
But if each child of the component is a paragraph, and you either want to show all the paragraphs when expanded, but only one paragraph when not expanded, you could do something like this:
import React, { useState } from "react";
export default function Expandable({ children, initial = false }) {
const [expanded, setExpanded] = useState(initial);
return (
<div>
{expanded ? children : [...children].slice(0,1)}
<button onClick={() => setExpanded(!expanded)}>{`Read ${
expanded ? "less" : "more"
}`}</button>
</div>
);
}
Then you could consume the component like this:
<Expandable>
<p>
egestas ultrices. Curabitur eget lorem eu augue pretium blandit at non
metus. Mauris a venenatis tellus, vel mollis leo. Vivamus nec
elementum neque, non mollis felis.
</p>
<p>
fringilla. Sed convallis sem sed diam vehicula egestas. In tincidunt
hendrerit elit, eu facilisis leo vulputate id. Sed rutrum imperdiet
convallis. Nam mi magna, lacinia vitae consequat vel, consequat eget
ex. Maecenas nec ex egestas, mattis orci sit amet, dictum sem. Sed id
tincidunt felis. Vivamus ipsum erat, sagittis sed consequat et,
molestie a risus. Quisque nec risus fringilla, pellentesque leo a,
venenatis leo.
</p>
<p>
est in varius pulvinar. Ut dignissim condimentum semper. Vestibulum
blandit purus vitae dapibus finibus. Nam iaculis metus orci, et
posuere lectus imperdiet at. Suspendisse non erat tortor.
</p>
<p>ullamcorper sagittis.</p>
</Expandable>
Edit:
You can get the height of the first paragraph like this.
Note: with this approach, you probably need to listen for a resize event and adjust the value of the height state.
import React, { useState, useEffect, useRef } from "react";
export default function Expandable({ children, initial = false }) {
const [expanded, setExpanded] = useState(initial);
const [firstParagraphHeight, setFirstParagraphHeight] = useState(0);
const ref = useRef(null);
useEffect(() => {
const height = ref.current.children[0].getBoundingClientRect().height;
setFirstParagraphHeight(height);
}, []);
return (
<>
<div
ref={ref}
style={{
overflow: "hidden",
maxHeight: expanded ? "none" : `${firstParagraphHeight}px`
}}
>
{children}
</div>
<button onClick={() => setExpanded(!expanded)}>{`Read ${
expanded ? "less" : "more"
}`}</button>
</>
);
}

JQuery Stop Text Flickering when Pressing Show Less / Show More

I have a number of user stories on my website page. I don't want to show the entirety of each story if the user doesn't want to read it, so I show the first 2 lines and there is a Show more link to press to see the whole story. The user can then press the link again to See less. The issue comes when the user clicks the Show less link, the story condenses and shows 2 lines, but there is a momentary flicker of say 2 additional lines (can't quite make it out as its there for a few milliseconds). And it is this that I don't want.
This is my HTML and jQuery which is loaded via Ajax Request.
$(document).ready(function() {
$(".content").on("click", ".showMore a", function() {
var $this = $(this);
var content = $this.parent().prev()
var linkText = $this.text().toUpperCase();
if (linkText === "SHOW MORE") {
linkText = "Show less";
content.switchClass("hideContent", "showContent", 400);
} else {
linkText = "Show more";
content.switchClass("showContent", "hideContent", 400);
}
$this.text(linkText);
});
});
.hideContent {
overflow: hidden;
line-height: 1em;
height: 4em;
}
.showContent {
line-height: 1em;
height: auto;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="content">
<div class="hideContent" style="">
<div class="post-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In id erat pharetra risus fermentum aliquam. Maecenas eu nisi posuere, rutrum orci et, imperdiet elit. Nulla tempor imperdiet sagittis. Aenean cursus justo ac enim lacinia vehicula. Etiam dictum
suscipit nibh, at iaculis velit lobortis vel. Duis pretium diam ut lectus mollis vehicula.</div>
<div class="post-action"><input type="button" value="Like" id="like_94" class="like"><span class="likesTotal" id="likes_94">0</span>
</div>
</div>
<div class="showMore"><a>Show more</a></div>
</div>
</div>
I hope that's what you wanted. You can do this easily by using .addClass and .removeClass
Also. if you content and stories display as exactly as the example in question then .parent() is not what you want you can call .prev() and it will work just find.
Simple Show and Hide
Using addClass and removeClass
Working Demo: https://jsfiddle.net/usmanmunir/cks8d067/
Run snippet below to see it working.
$(document).ready(function() {
$(".showMore").on("click", function() {
var $this = $(this);
var content = $this.prev()
var linkText = $this.text().toUpperCase();
if (linkText === "SHOW MORE") {
linkText = "Show less";
content.addClass("showContent").removeClass("hideContent");
} else {
content.addClass("hideContent").removeClass("showContent");
linkText = "Show more";
}
$this.text(linkText);
});
});
.hideContent {
overflow: hidden;
line-height: 1em;
height: 2em;
}
.showContent {
line-height: 1em;
height: auto;
}
.showMore {
cursor: pointer;
}
<div class="hideContent">
<div class="post-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In id erat pharetra risus fermentum aliquam. Maecenas eu nisi posuere, rutrum orci et, imperdiet elit. Nulla tempor imperdiet sagittis. Aenean cursus justo ac enim lacinia vehicula. Etiam dictum
suscipit nibh, at iaculis velit lobortis vel. Duis pretium diam ut lectus mollis vehicula.</div>
<div class="post-action"><input type="button" value="Like" id="like_94" class="like"><span class="likesTotal" id="likes_94">0</span>
</div>
</div>
<div class="showMore"><a>Show more</a></div>
Accordion Effects
Using accordion effect we can use .animate and .css
To do the accordion effects we can use .animate and .css for height to show more or less of the story. We will use .siblings
Working Fiddle: https://jsfiddle.net/usmanmunir/ovgah34z/
$(document).ready(function() {
$(".content").on("click", '.showMore', function() {
var $this = $(this);
var content = $this.prev()
var linkText = $this.text().toUpperCase();
if (linkText === "SHOW MORE") {
linkText = "Show less";
$this.siblings('div').css('height', 'auto');
var currHeight = $this.siblings('div').height();
$this.siblings('div').css('height', '2em');
$this.siblings('div').animate({
height: currHeight
}, 500);
} else {
$this.siblings('div').animate({
height: '2em'
}, 500);
linkText = "Show more";
}
$this.text(linkText);
});
});
.hideContent {
overflow: hidden;
line-height: 1em;
height: 2em;
}
.showContent {
line-height: 1em;
height: auto;
}
.showMore {
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="content">
<div class="hideContent">
<div class="post-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In id erat pharetra risus fermentum aliquam. Maecenas eu nisi posuere, rutrum orci et, imperdiet elit. Nulla tempor imperdiet sagittis. Aenean cursus justo ac enim lacinia vehicula. Etiam dictum
suscipit nibh, at iaculis velit lobortis vel. Duis pretium diam ut lectus mollis vehicula.</div>
<div class="post-action"><input type="button" value="Like" id="like_94" class="like"><span class="likesTotal" id="likes_94">0</span>
</div>
</div>
<div class="showMore"><a>Show more</a></div>
</div>
Let me know.
Here is an example of toggle inside a custom function .
If this is the result that you want .
Do not forget to mark my answer as the right answer!
Regards
function makeTheMagic(){
$("#extraContent").toggle();
let btnText= $("#btnAction").text() == "Show More!"?"Show Less!":"Show More!";
$("#btnAction").text(btnText);
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='card'>
<div class='card-body'>
<p class='alert-success'>
In my situation I want to show the first 2 sentences and then show the rest of the text with a toggle, but I couldn't find any examples of this. Did you have any examples of this? Thank you.
</p>
<p class='alert-danger' style='display:none' id='extraContent'>
I have a number of user stories on my website page. I don't want to show the entirety of each story if the user doesn't want to read it, so I show the first 2 lines and there is a Show more link to press to see the whole story. The user can then press the link again to See less. The issue comes when the user clicks the Show less link, the story condenses and shows 2 lines, but there is a momentary flicker of say 2 additional lines (can't quite make it out as its there for a few milliseconds). And it is this that I don't want.
</p>
<span class='btn btn-outline-success' onclick='makeTheMagic()' id='btnAction'>Show More!</span>
</div>
</div>

Placing text on Google Maps

im trying to place text on top of Google Maps (an API). Right now the text is being placed above the maps in a separate section. I have tried position:absolute, but then it places behind the maps.
This is how it looks now: https://jsfiddle.net/uy2jza2k/1/
I want it to look like this: https://gyazo.com/dbacba06c463c4ec09504a0f62d44a36
HTML
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>onepageskiw</title>
<link href="styles.css" rel="stylesheet" type="text/css">
<script src="js.js"></script>
</head>
<body>
<div id="billede">
<div>
<nav>
<ul id="menu">
<li>Top</li>
<li>Om Eventet</li>
<li>Lokation</li>
<li>Kontakt</li>
</ul>
</nav>
</div>
<div id="logodiv">
<img src="design/logotop.png">
</div>
<div id="overskrift">
<h1>EVENTET STARTER OM</h1>
</div>
<div id="countdowner">
<table id="table">
<tr>
<div id="countdown">
<td id="id1"></td>
<td id="id2"></td>
<td id="id3"></td>
<td id="id4"></td>
</div>
<tr>
<tr>
<td class="timeLabel">DAGE</td>
<td class="timeLabel">TIMER</td>
<td class="timeLabel">MIN</td>
<td class="timeLabel">SEK</td>
</tr>
</tr>
</tr>
</table>
</div>
</div>
<h2>Hvad skal der ske?</h2>
<hr></hr>
<div id="infoydre">
<div id="information">
<p>Lorem ipsum dolor sit amet, duis facilisis eu, condimentum et mollis risus viverra adipiscing tristique. A ultricies, augue nibh scelerisque turpis consequat. Sapien id dui nulla quam viverra erat, sit sed, purus pulvinar amet justo. Dui nam at justo, ultricies id facilisis est non. Et vitae eget mi, pede sit duis orci eros corrupti. Tellus sem id
<br><br>
eget nam vel pede. Sed purus pharetra in sollicitudin suspendisse pellentesque, nec risus arcu nonummy, curabitur hymenaeos eu. Rutrum aliquet, et sit ut integer praesent sit cras, aliquet molestie pellentesque neque quam luctus odio</p>
<p>Lorem ipsum dolor sit amet, duis facilisis eu, condimentum et mollis risus viverra adipiscing tristique. A ultricies, augue nibh scelerisque turpis consequat.
<br><br>
Sapien id dui nulla quam viverra erat, sit sed, purus pulvinar amet justo. Dui nam at justo, ultricies id facilisis est non. Et vitae eget mi, pede sit duis orci eros corrupti. Tellus sem id. eget nam vel pede. Sed purus pharetra in sollicitudin suspendisse pellentesque, nec risus arcu nonummy, curabitur hymenaeos eu. Rutrum aliquet, et sit ut integer praesent sit cras, aliquet molestie pellentesque neque quam luctus odio</p>
</div>
</div>
<div id="sikkerydre">
<div id="sikkerindre">
<h2>Sikkerhed</h2>
<hr></hr>
<p>arrangementet vil være under fuldt opsyn af de lækreste
babes skive har at tilbyde med.<br> pharetra in sollicitudin suspendisse pellentesque, nec risus </p>
</div>
</div>
<div class="section group">
<div class="col span_1_of_2">
<h2 id="hvid2">Test</h2>
<style type="text/css">
/* Set a size for our map container, the Google Map will take up 100% of this container */
#map {
width: 100%;
height: 100%;
}
</style>
<!--
You need to include this script tag on any page that has a Google Map.
The following script tag will work when opening this example locally on your computer.
But if you use this on a localhost server or a live website you will need to include an API key.
Sign up for one here (it's free for small usage):
https://developers.google.com/maps/documentation/javascript/tutorial#api_key
After you sign up, use the following script tag with YOUR_GOOGLE_API_KEY replaced with your actual key.
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOUR_GOOGLE_API_KEY"></script>
-->
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js"></script>
<script type="text/javascript">
// When the window has finished loading create our google map below
google.maps.event.addDomListener(window, 'load', init);
function init() {
// Basic options for a simple Google Map
// For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions
var mapOptions = {
// How zoomed in you want the map to start at (always required)
scrollwheel: false,
navigationControl: false,
zoomControlOptions: false,
zoomControl: false,
mapTypeControl: false,
zoom: 15,
// The latitude and longitude to center the map (always required)
center: new google.maps.LatLng(56.5760701, 9.0522028,591), // New York
// How you would like to style the map.
// This is where you would paste any style found on Snazzy Maps.
styles: [{"featureType":"all","elementType":"labels.text.fill","stylers":[{"saturation":36},{"color":"#000000"},{"lightness":40}]},{"featureType":"all","elementType":"labels.text.stroke","stylers":[{"visibility":"on"},{"color":"#000000"},{"lightness":16}]},{"featureType":"all","elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"administrative","elementType":"geometry.fill","stylers":[{"color":"#000000"},{"lightness":20}]},{"featureType":"administrative","elementType":"geometry.stroke","stylers":[{"color":"#000000"},{"lightness":17},{"weight":1.2}]},{"featureType":"landscape","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":20}]},{"featureType":"poi","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":21}]},{"featureType":"road.highway","elementType":"geometry.fill","stylers":[{"color":"#000000"},{"lightness":17}]},{"featureType":"road.highway","elementType":"geometry.stroke","stylers":[{"color":"#000000"},{"lightness":29},{"weight":0.2}]},{"featureType":"road.arterial","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":18}]},{"featureType":"road.local","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":16}]},{"featureType":"transit","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":19}]},{"featureType":"water","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":17}]}]
};
// Get the HTML DOM element that will contain your map
// We are using a div with id="map" seen below in the <body>
var mapElement = document.getElementById('map');
// Create the Google Map using our element and options defined above
var map = new google.maps.Map(mapElement, mapOptions);
// Let's also add a marker while we're at it
var marker = new google.maps.Marker({
position: new google.maps.LatLng(56.5760701, 9.0522028,591),
map: map,
title: 'Surf & Grill Strandvejen'
});
}
</script>
<!-- The element that will contain our Google Map. This is used in both the Javascript and CSS above. -->
<div id="map"></div>
</div>
<div class="col span_1_of_2">
<img width="100%" src="design/squarebox.jpg">
</div>
</div>
<div class="section group">
<div class="col span_1_of_2">
<img width="100%" src="design/squarebox2.png">
</div>
<div class="col span_1_of_2">
<h2 id="hvid">Besøg vores Facebook</h2>
<hr></hr>
<p>Hej med dig</p>
</div>
</div>
</body>
</html>
<script>
CountDownTimer('06/25/2016 10:00 AM', 'id');
function CountDownTimer(dt, id)
{
var end = new Date(dt);
var _second = 1000;
var _minute = _second * 60;
var _hour = _minute * 60;
var _day = _hour * 24;
var timer;
function showRemaining() {
var now = new Date();
var distance = end - now;
if (distance < 0) {
clearInterval(timer);
document.getElementById(id).innerHTML = 'EXPIRED!';
return;
}
var days = Math.floor(distance / _day);
var hours = Math.floor((distance % _day) / _hour);
var minutes = Math.floor((distance % _hour) / _minute);
var seconds = Math.floor((distance % _minute) / _second);
document.getElementById(id+"1").innerHTML = days;
document.getElementById(id+"2").innerHTML = hours;
document.getElementById(id+"3").innerHTML = minutes;
document.getElementById(id+"4").innerHTML = seconds;
}
timer = setInterval(showRemaining, 1000);
}
</script>
CSS
#charset "utf-8";
#import url(https://fonts.googleapis.com/css?family=Montserrat:400|Raleway:400,500,600,700,800|);
body {
margin:0;
}
#billede {
background:url(baggrund.jpg) no-repeat;
background-size: cover;
height: 100vh;
/*background-position: top center;*/
}
#logodiv {
float: left;
text-align:center;
width:100%;
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-220%);
}
#logodiv>img {
width:15em;
}
h1 {
font-family:raleway;
font-weight:100;
width:100%;
text-align:center;
color:white;
letter-spacing:11px;
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-230%);
font-size:2.5em;
white-space: nowrap;
}
#countdowner {
font-family:sans-serif;
color:white;
position:absolute;
margin:0;
padding:0;
width:100%;
font-size:2em;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-20%);
}
#id1 {
font-size:2.5em;
}
#id2 {
font-size:2.5em;
}
#id3 {
font-size:2.5em;
}
#id4 {
font-size:2.5em;
}
.timeLabel {
font-size:0.7em;
color:#f1a01e;
font-family:montserrat;
font-weight:700;
}
#table {
margin:0 auto;
text-align:center;
}
#table td{
padding:0px 45px;
}
#menu {
position:absolute;
padding:0;
width:100%;
bottom:0;
text-align:center;
float: left;
}
#menu>li {
font-size:20px;
list-style:none;
display:inline-block;
text-transform:uppercase;
letter-spacing:3px;
font-family:raleway;
font-weight:400;
}
#menu>li>a {
padding:0 15px;
text-decoration:none;
color:white;
}
#menu>li>a:hover {
color:#f1a01e;
}
h2 {
text-align: center;
font-size: 2.2em;
font-family:raleway;
text-transform: uppercase;
letter-spacing: 3px;
font-weight: 700;
margin: 0;
padding-top: 70px;
color: #171717;
padding-bottom: 10px;
white-space: nowrap;
color:black;
}
p {
color: #171717;
margin: 0;
line-height: 35px;
font-size: 23px;
letter-spacing: 2px;
font-family: raleway;
}
hr {
width: 160px;
height: 5px;
background-color: #4bc9f4;
border: 0;
}
#infoydre {
width: 100%;
}
#information {
margin: auto;
width: 80%;
padding-top: 40px;
padding-bottom: 90px;
left:0;
right: 0;
top: 0;
bottom: 0;
column-count: 2;
}
#sikkerydre {
background:url(sikkerhed.jpg) no-repeat;
background-size: cover;
width: 100%;
}
#sikkerindre {
margin: auto;
width: 80%;
left:0;
right: 0;
top: 0;
bottom: 0;
text-align: center;
}
#sikkerindre>p {
padding-top: 40px;
padding-bottom: 90px;
}
/* SECTIONS */
.section {
clear: both;
padding: 0px;
margin: 0px;
}
/* COLUMN SETUP */
.col {
display: block;
float:left;
margin: 0% 0 0% 0%;
height:30vw;
}
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after { content:""; display:table; }
.group:after { clear:both;}
.group { zoom:1; /* For IE 6/7 */ }
/* GRID OF TWO */
.span_2_of_2 {
width: 100%;
}
.span_1_of_2 {
width: 50%;
background-color:#363636;
overflow:hidden;
}
/* GO FULL WIDTH AT LESS THAN 480 PIXELS */
#hvid {
color:white;
}
#hvid2 {
color:white;
position:relative;
}
Try adding:
z-index:99;
to the text. This should ensure that it appears in front the map instead of behind

AS3 htmlText in TLFTextField with CSS <a> and <h> tag bugs

Firstly, I know as3 doesn't like css or html and that there's about a billion questions on this forum alone about it, but after searching and searching I can't seem to find anything like what I'm experiencing. Please forgive me if this is painfully obvious to answer/has been answered already.
The Situation
I have a project made in Flash CS6 with the coding on the timeline (I know this is bad, but it's too late to change)
The project is importing a wordpress page that has been exported to an RSS feed and imported in flash as an xml file
A TLF textfield (I can get it working with classic textfields, but want to try to get it to work with TLF for various reasons) is created and a loaded CSS sheet is applied via .stylesheet = and the text is set via .htmlText =
The Problems
There are a few glitches in the rendering of the text. I know Flash doesn't support all css tags, but even the basic ones aren't quite working. The exact problems are:
A heading followed by a heading (i.e. < /h1>< h2>) is merged to the preceding heading (so both are formatted as < h1>), adding a < p/> tag between them seems to fix this, but adds a line break :/
Bold and italic tags are proving difficult, replacing < strong> and < em> with < b> and < i> makes them work by themselves, but when they're mixed together (like this) they stop working altogether
This is my main problem: links are always in blue, no matter what the CSS says, despite a:hover being correct (fix this and I could live with everything else)
I think the problem lies in my code somewhere, so here's the as3:
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.text.TextField;
import flash.events.ProgressEvent;
import fl.text.TLFTextField;
var fonts:Array = Font.enumerateFonts();
for each (var font:Font in fonts)
{
trace( font.fontName+":"+font.fontType );
}
var rss_xml:XML = new XML();
var test_txt:TLFTextField = new TLFTextField ;
with (test_txt)
{
antiAliasType = AntiAliasType.ADVANCED;
width = 940;
height = 600;
x = 0;
y = 0;
autoSize = TextFieldAutoSize.LEFT;
wordWrap = true;
embedFonts = true;
}
var sulsc_style:StyleSheet = new StyleSheet();
var css_loader:URLLoader = new URLLoader();
css_loader.load(new URLRequest("sulsc_style.css"));
css_loader.addEventListener(Event.COMPLETE, onCSSComplete);
function onCSSComplete(e:Event):void
{
sulsc_style.parseCSS(e.target.data);
rss_xml.ignoreWhitespace = false;
var rss_loader:URLLoader = new URLLoader(new URLRequest("http://news.sulsc.org/feed"));
rss_loader.addEventListener(Event.COMPLETE,rss_loaded);
l.mode = "manual";
rss_loader.addEventListener(ProgressEvent.PROGRESS,rss_load);
}
function rss_load(e:ProgressEvent):void
{
//trace(e.bytesLoaded/(113*1024));
l.setProgress(e.bytesLoaded,(113*1024));
}
function rss_loaded(e:Event):void
{
removeChild(l);
l = null;
rss_xml = XML(e.target.data);
rss_xml.ignoreWhiteSpace = true;
var rss_raw:String = String(rss_xml);
rss_raw = rss_raw.split(":encoded").join("");
rss_raw = rss_raw.split("\n").join("");
rss_raw = rss_raw.split("</h1><h2>").join("</h1><p/><h2>");
rss_raw = rss_raw.split("</h2><h3>").join("</h2><p/><h3>");
rss_raw = rss_raw.split("</h3><h4>").join("</h3><p/><h4>");
rss_raw = rss_raw.split("</h4><h5>").join("</h4><p/><h5>");
rss_raw = rss_raw.split("<strong>").join("<b>");
rss_raw = rss_raw.split("</strong>").join("</b>");
rss_raw = rss_raw.split("<em>").join("<i>");
rss_raw = rss_raw.split("</em>").join("</i>");
rss_xml = XML(rss_raw);
test_txt.styleSheet = sulsc_style;
test_txt;
test_txt.htmlText = rss_xml.channel.item.(guid == "http://news.sulsc.org/?page_id=656").content;
addChild(test_txt);
}
Here's the XML that it's reading:
<h1>Heading 1</h1><p/><h2>Heading 2</h2><p/><h3>Heading 3</h3><p/><h4>Heading 4</h4><p><a title="SULSC" href="http://www.sulsc.org">Isolated link.</a></p><p>Paragraph. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In nibh risus, elementum in tempor non, <a title="SULSC" href="http://www.sulsc.org">normal link</a>. Donec consequat arcu in nulla rhoncus aliquam. Fusce eu leo nunc, eget tempus risus. Aliquam imperdiet, sem non euismod blandit, nisi sapien pharetra leo, ac facilisis velit purus nec <i><b>bold italic</b></i>. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales vulputate interdum. <del>Strikethrough</del> congue, purus ut rhoncus porttitor, erat velit iaculis libero, nec commodo leo dui eget ante. Vivamus volutpat sollicitudin vulputate.</p><blockquote><p>Block quote. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In nibh risus, elementum in tempor non, malesuada ac nisl. Donec consequat arcu in nulla rhoncus aliquam. Fusce eu leo nunc, eget tempus risus. Aliquam imperdiet, sem non euismod blandit, nisi sapien pharetra leo, ac facilisis velit purus nec tellus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales vulputate interdum. Vestibulum congue, purus ut rhoncus porttitor, erat velit iaculis libero, nec commodo leo dui eget ante. Vivamus volutpat sollicitudin vulputate.</p></blockquote><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In nibh risus, elementum in tempor non, malesuada ac nisl. Donec consequat arcu in nulla rhoncus aliquam. Fusce eu leo nunc, eget tempus risus. <i>Italic</i> imperdiet, sem non euismod blandit, nisi sapien pharetra leo, ac facilisis velit purus nec tellus. <b>BOLD</b> aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Link sodales vulputate interdum. Vestibulum congue, <b><i>BOLD ITALIC LINK</i></b> ut rhoncus porttitor, erat velit iaculis libero, nec commodo leo dui eget ante. Vivamus volutpat sollicitudin vulputate.</p><ol><li>Numbered list</li><li>Number two</li><li>Number three</li></ol>
And here's the CSS that's being applied:
/*
leading is line height
*/
p, ol, ul, li, body {
font-family: Fontin Sans Rg;
font-size: 12pt;
color: #666666;
text-align: justify;
}
h1 {
font-family: Nilland;
font-size: 30pt;
text-align:left;
color: #999999;
}
h2 {
font-family: Nilland;
font-size: 20pt;
color: #ff9900;
margin-left:25px;
letter-spacing: 1px;
}
h3 {
font-family: GeosansLight;
font-size: 16pt;
text-align:left;
color: #999999;
margin-left:50px;
letter-spacing: 1px;
}
h4, h5, h6 {
font-family: GeosansLight;
font-size: 14pt;
text-align:left;
color: #999999;
margin-left:75px;
letter-spacing: 1px;
}
ol, ul, li {
margin-left: 50px;
}
b-quote,blockquote {
font-family: Fontin Sans Rg;
font-style:italic;
color:#999999;
margin-left: 100px;
margin-right: 100px;
}
a, {
text-decoration: underline;
color: #666666;
}
a:hover {
color: #FF9900;
text-decoration: underline;
}
Combined they produce this:
If you have idea what I'm doing wrong, please let me know, but I am a complete novice so layman's terms would be appreciated (:
Like you said, Flash has its problems with StyleSheets. Maybe you should try setting the style direct in as3! Always worked for me!
var style:StyleSheet = new StyleSheet();
var hover:Object = new Object();
hover.color = "#FF9900";
var link:Object = new Object();
link.fontWeight = "bold";
link.textDecoration= "underline";
link.color = "#00FF00"; //green
style.setStyle("a:link", link);
style.setStyle("a:hover", hover);
html_txt.styleSheet = style;
That to the link problem! For the otherones i would have to test it myself, i'll update the answer when i do! But you could try and set all your Style attributes in as3.
Using a:link in the CSS sets the link style in flash.
Inserting a paragraph tag with a specific style (one that has no line height) effectively fixes the headings issue.
Haven't figured out bold and italic, but that's not really a major worry. If anyone does, let me know!
Here's the current working code for anyone who's interested:
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.text.TextField;
import flash.events.ProgressEvent;
import fl.text.TLFTextField;
var fonts:Array = Font.enumerateFonts();
for each (var font:Font in fonts)
{
trace( font.fontName+":"+font.fontType );
}
var rss_xml:XML = new XML();
var test_txt:TLFTextField = new TLFTextField ;
with (test_txt)
{
antiAliasType = AntiAliasType.ADVANCED;
width = 940;
height = 600;
x = 0;
y = 0;
autoSize = TextFieldAutoSize.LEFT;
wordWrap = true;
embedFonts = true;
}
var sulsc_style:StyleSheet = new StyleSheet();
var css_loader:URLLoader = new URLLoader();
css_loader.load(new URLRequest("sulsc_style.css"));
css_loader.addEventListener(Event.COMPLETE, onCSSComplete);
function onCSSComplete(e:Event):void
{
sulsc_style.parseCSS(e.target.data);
rss_xml.ignoreWhitespace = false;
var rss_loader:URLLoader = new URLLoader(new URLRequest("http://news.sulsc.org/feed"));
rss_loader.addEventListener(Event.COMPLETE,rss_loaded);
l.mode = "manual";
rss_loader.addEventListener(ProgressEvent.PROGRESS,rss_load);
}
function rss_load(e:ProgressEvent):void
{
//trace(e.bytesLoaded/(113*1024));
l.setProgress(e.bytesLoaded,(113*1024));
}
function rss_loaded(e:Event):void
{
removeChild(l);
l = null;
rss_xml = XML(e.target.data);
rss_xml.ignoreWhiteSpace = true;
var rss_raw:String = String(rss_xml);
rss_raw = rss_raw.split(":encoded").join("");
rss_raw = rss_raw.split("\n").join("");
rss_raw = rss_raw.split('<p style="text-align: right;">').join('<p class="right">');
rss_raw = rss_raw.split('<p style="text-align: center;">').join('<p class="centre">');
rss_raw = rss_raw.split('<p style="text-align: left;">').join('<p class="left">');
rss_raw = rss_raw.split('<p style="text-align: justify;">').join('<p class="just">');
var heading_replace:RegExp = new RegExp("(</h[0-9]>)(<h[0-9]>)","g9");
var underline_replace:RegExp = new RegExp('<span style="text-decoration: underline;">(.*?)</span>',"gi");
var bold_replace:RegExp = new RegExp('<strong>(.*?)</strong>',"gi");
var italic_replace:RegExp = new RegExp('<em>(.*?)</em>',"gi");
rss_raw = rss_raw.replace(heading_replace,'$1<p class="space"></p>$2');
rss_raw = rss_raw.replace(underline_replace,'<u>$1</u>');
rss_raw = rss_raw.replace(bold_replace,'<b>$1</b>');
rss_raw = rss_raw.replace(italic_replace,'<i>$1</i>');
rss_xml = XML(rss_raw);
test_txt.styleSheet = sulsc_style;
test_txt.htmlText = rss_xml.channel.item.(guid == "http://news.sulsc.org/?page_id=400").content;
addChild(test_txt);
}
and the CSS:
/*
flash doesn't support:
-bold and italic
-strikethrough
*/
p, ol, ul, li, body {
font-family: Fontin Sans Rg;
font-size: 12pt;
color: #666666;
text-align: justify;
padding-bottom: 12px;
padding-top: 6px;
}
h1 {
font-family: Nilland;
font-size: 30pt;
text-align:left;
color: #999999;
}
h2 {
font-family: Nilland;
font-size: 20pt;
color: #ff9900;
margin-left:25px;
letter-spacing: 1px;
}
h3 {
font-family: GeosansLight;
font-size: 16pt;
text-align:left;
color: #999999;
margin-left:50px;
letter-spacing: 1px;
}
h4, h5, h6 {
font-family: GeosansLight;
font-size: 14pt;
text-align:left;
color: #999999;
margin-left:75px;
letter-spacing: 1px;
}
ol, ul, li {
margin-left: 50px;
line-height:5px
}
b-quote,blockquote {
font-family: Fontin Sans Rg;
font-style:italic;
color:#999999;
margin-left: 100px;
margin-right: 100px;
padding-bottom: 12px;
}
a:link {
text-decoration: underline;
color: #666666;
}
a:hover {
color: #FF9900;
text-decoration: underline;
}
/* DO NOT DELETE THESE */
.space {
line-height:1px;
padding-bottom: 0px;
padding-top:0px;
}
.right {
text-align:right;
}
.centre {
text-align:center;
}
.left {
text-align:left;
}
.just {
text-align:justify;
}
Which makes:
Thanks for your help!
On the bold/italic issue, we found that we needed to have entirely separate fonts/classes to handle them. So you will need to export one each of a regular, italicized and bold styled font, and then wrap the appropriate sections in font tags. We use and to do a find/replace adding parentClassName_italic to the font tag, and then point to the exported font in the css. A real pita, but there you go.